@@ -311,7 +311,7 @@ def init_notebook_mode(connected=False):
311311
312312
313313def _plot_html (figure_or_data , config , validate , default_width ,
314- default_height , global_requirejs ):
314+ default_height , global_requirejs , auto_play ):
315315
316316 figure = tools .return_figure_from_figure_or_data (figure_or_data , validate )
317317
@@ -348,13 +348,20 @@ def _plot_html(figure_or_data, config, validate, default_width,
348348 'https://plot.ly' )
349349
350350 if jframes :
351+ if auto_play :
352+ animate = (".then(function(){" +
353+ "Plotly.animate('{id}');" .format (id = plotdivid ) +
354+ "})" )
355+ else :
356+ animate = ''
357+
351358 script = '''
352359 Plotly.plot(
353360 '{id}',
354361 {data},
355362 {layout},
356363 {config}
357- ).then(function () {add_frames}).then(function() {animate})
364+ ).then(function () {add_frames}){animate}
358365 ''' .format (
359366 id = plotdivid ,
360367 data = jdata ,
@@ -363,7 +370,7 @@ def _plot_html(figure_or_data, config, validate, default_width,
363370 add_frames = "{" + "return Plotly.addFrames('{id}',{frames}" .format (
364371 id = plotdivid , frames = jframes
365372 ) + ");}" ,
366- animate = "{" + "Plotly. animate('{id}');" . format ( id = plotdivid ) + "}"
373+ animate = animate
367374 )
368375 else :
369376 script = 'Plotly.newPlot("{id}", {data}, {layout}, {config})' .format (
@@ -397,7 +404,7 @@ def _plot_html(figure_or_data, config, validate, default_width,
397404
398405def iplot (figure_or_data , show_link = False , link_text = 'Export to plot.ly' ,
399406 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 ):
401408 """
402409 Draw plotly graphs inside an IPython or Jupyter notebook without
403410 connecting to an external server.
@@ -433,6 +440,9 @@ def iplot(figure_or_data, show_link=False, link_text='Export to plot.ly',
433440 config (default=None) -- Plot view options dictionary. Keyword arguments
434441 `show_link` and `link_text` set the associated options in this
435442 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.
436446
437447 Example:
438448 ```
@@ -473,8 +483,7 @@ def iplot(figure_or_data, show_link=False, link_text='Export to plot.ly',
473483
474484 if __PLOTLY_OFFLINE_INITIALIZED :
475485 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 )
478487 resize_script = ''
479488 if width == '100%' or height == '100%' :
480489 resize_script = _build_resize_script (
@@ -515,7 +524,7 @@ def plot(figure_or_data, show_link=False, link_text='Export to plot.ly',
515524 validate = True , output_type = 'file' , include_plotlyjs = True ,
516525 filename = 'temp-plot.html' , auto_open = True , image = None ,
517526 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 ):
519528 """ Create a plotly graph locally as an HTML document or string.
520529
521530 Example:
@@ -625,6 +634,9 @@ def plot(figure_or_data, show_link=False, link_text='Export to plot.ly',
625634 If a string that ends in '.js', a script tag is included that
626635 references the specified path. This approach can be used to point the
627636 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.
628640 """
629641 if output_type not in ['div' , 'file' ]:
630642 raise ValueError (
@@ -642,7 +654,7 @@ def plot(figure_or_data, show_link=False, link_text='Export to plot.ly',
642654
643655 plot_html , plotdivid , width , height = _plot_html (
644656 figure_or_data , config , validate ,
645- '100%' , '100%' , global_requirejs = False )
657+ '100%' , '100%' , global_requirejs = False , auto_play = auto_play )
646658
647659 # Build resize_script
648660 resize_script = ''
0 commit comments