@@ -311,7 +311,7 @@ def init_notebook_mode(connected=False):
311
311
312
312
313
313
def _plot_html (figure_or_data , config , validate , default_width ,
314
- default_height , global_requirejs ):
314
+ default_height , global_requirejs , auto_play ):
315
315
316
316
figure = tools .return_figure_from_figure_or_data (figure_or_data , validate )
317
317
@@ -348,13 +348,20 @@ def _plot_html(figure_or_data, config, validate, default_width,
348
348
'https://plot.ly' )
349
349
350
350
if jframes :
351
+ if auto_play :
352
+ animate = (".then(function(){" +
353
+ "Plotly.animate('{id}');" .format (id = plotdivid ) +
354
+ "})" )
355
+ else :
356
+ animate = ''
357
+
351
358
script = '''
352
359
Plotly.plot(
353
360
'{id}',
354
361
{data},
355
362
{layout},
356
363
{config}
357
- ).then(function () {add_frames}).then(function() {animate})
364
+ ).then(function () {add_frames}){animate}
358
365
''' .format (
359
366
id = plotdivid ,
360
367
data = jdata ,
@@ -363,7 +370,7 @@ def _plot_html(figure_or_data, config, validate, default_width,
363
370
add_frames = "{" + "return Plotly.addFrames('{id}',{frames}" .format (
364
371
id = plotdivid , frames = jframes
365
372
) + ");}" ,
366
- animate = "{" + "Plotly. animate('{id}');" . format ( id = plotdivid ) + "}"
373
+ animate = animate
367
374
)
368
375
else :
369
376
script = 'Plotly.newPlot("{id}", {data}, {layout}, {config})' .format (
@@ -397,7 +404,7 @@ def _plot_html(figure_or_data, config, validate, default_width,
397
404
398
405
def iplot (figure_or_data , show_link = False , link_text = 'Export to plot.ly' ,
399
406
validate = True , image = None , filename = 'plot_image' , image_width = 800 ,
400
- image_height = 600 , config = None ):
407
+ image_height = 600 , config = None , auto_play = True ):
401
408
"""
402
409
Draw plotly graphs inside an IPython or Jupyter notebook without
403
410
connecting to an external server.
@@ -433,6 +440,9 @@ def iplot(figure_or_data, show_link=False, link_text='Export to plot.ly',
433
440
config (default=None) -- Plot view options dictionary. Keyword arguments
434
441
`show_link` and `link_text` set the associated options in this
435
442
dictionary if it doesn't contain them already.
443
+ auto_play (default=True) -- Whether to automatically start the animation
444
+ sequence if the figure contains frames. Has no effect if the figure
445
+ does not contain frames.
436
446
437
447
Example:
438
448
```
@@ -473,8 +483,7 @@ def iplot(figure_or_data, show_link=False, link_text='Export to plot.ly',
473
483
474
484
if __PLOTLY_OFFLINE_INITIALIZED :
475
485
plot_html , plotdivid , width , height = _plot_html (
476
- figure_or_data , config , validate , '100%' , 525 , True
477
- )
486
+ figure_or_data , config , validate , '100%' , 525 , True , auto_play )
478
487
resize_script = ''
479
488
if width == '100%' or height == '100%' :
480
489
resize_script = _build_resize_script (
@@ -515,7 +524,7 @@ def plot(figure_or_data, show_link=False, link_text='Export to plot.ly',
515
524
validate = True , output_type = 'file' , include_plotlyjs = True ,
516
525
filename = 'temp-plot.html' , auto_open = True , image = None ,
517
526
image_filename = 'plot_image' , image_width = 800 , image_height = 600 ,
518
- config = None , include_mathjax = False ):
527
+ config = None , include_mathjax = False , auto_play = True ):
519
528
""" Create a plotly graph locally as an HTML document or string.
520
529
521
530
Example:
@@ -625,6 +634,9 @@ def plot(figure_or_data, show_link=False, link_text='Export to plot.ly',
625
634
If a string that ends in '.js', a script tag is included that
626
635
references the specified path. This approach can be used to point the
627
636
resulting HTML file to an alternative CDN.
637
+ auto_play (default=True) -- Whether to automatically start the animation
638
+ sequence on page load if the figure contains frames. Has no effect if
639
+ the figure does not contain frames.
628
640
"""
629
641
if output_type not in ['div' , 'file' ]:
630
642
raise ValueError (
@@ -642,7 +654,7 @@ def plot(figure_or_data, show_link=False, link_text='Export to plot.ly',
642
654
643
655
plot_html , plotdivid , width , height = _plot_html (
644
656
figure_or_data , config , validate ,
645
- '100%' , '100%' , global_requirejs = False )
657
+ '100%' , '100%' , global_requirejs = False , auto_play = auto_play )
646
658
647
659
# Build resize_script
648
660
resize_script = ''
0 commit comments