@@ -162,8 +162,15 @@ def init_notebook_mode(connected=False):
162
162
163
163
def _plot_html (figure_or_data , show_link , link_text , validate ,
164
164
default_width , default_height , global_requirejs ):
165
-
166
- figure = tools .return_figure_from_figure_or_data (figure_or_data , validate )
165
+ # force no validation if frames is in the call
166
+ if 'frames' in figure_or_data :
167
+ figure = tools .return_figure_from_figure_or_data (
168
+ figure_or_data , False
169
+ )
170
+ else :
171
+ figure = tools .return_figure_from_figure_or_data (
172
+ figure_or_data , validate
173
+ )
167
174
168
175
width = figure .get ('layout' , {}).get ('width' , default_width )
169
176
height = figure .get ('layout' , {}).get ('height' , default_height )
@@ -185,6 +192,8 @@ def _plot_html(figure_or_data, show_link, link_text, validate,
185
192
plotdivid = uuid .uuid4 ()
186
193
jdata = json .dumps (figure .get ('data' , []), cls = utils .PlotlyJSONEncoder )
187
194
jlayout = json .dumps (figure .get ('layout' , {}), cls = utils .PlotlyJSONEncoder )
195
+ if 'frames' in figure_or_data :
196
+ jframes = json .dumps (figure .get ('frames' , {}), cls = utils .PlotlyJSONEncoder )
188
197
189
198
config = {}
190
199
config ['showLink' ] = show_link
@@ -204,11 +213,30 @@ def _plot_html(figure_or_data, show_link, link_text, validate,
204
213
link_text = link_text .replace ('plot.ly' , link_domain )
205
214
config ['linkText' ] = link_text
206
215
207
- script = 'Plotly.newPlot("{id}", {data}, {layout}, {config})' .format (
208
- id = plotdivid ,
209
- data = jdata ,
210
- layout = jlayout ,
211
- config = jconfig )
216
+ if 'frames' in figure_or_data :
217
+ script = '''
218
+ Plotly.plot(
219
+ '{id}',
220
+ {data},
221
+ {layout},
222
+ {config}
223
+ ).then(function () {add_frames}).then(function(){animate})
224
+ ''' .format (
225
+ id = plotdivid ,
226
+ data = jdata ,
227
+ layout = jlayout ,
228
+ config = jconfig ,
229
+ add_frames = "{" + "return Plotly.addFrames('{id}',{frames}" .format (
230
+ id = plotdivid , frames = jframes
231
+ ) + ");}" ,
232
+ animate = "{" + "Plotly.animate('{id}');" .format (id = plotdivid ) + "}"
233
+ )
234
+ else :
235
+ script = 'Plotly.newPlot("{id}", {data}, {layout}, {config})' .format (
236
+ id = plotdivid ,
237
+ data = jdata ,
238
+ layout = jlayout ,
239
+ config = jconfig )
212
240
213
241
optional_line1 = ('require(["plotly"], function(Plotly) {{ '
214
242
if global_requirejs else '' )
@@ -232,6 +260,7 @@ def _plot_html(figure_or_data, show_link, link_text, validate,
232
260
233
261
return plotly_html_div , plotdivid , width , height
234
262
263
+
235
264
def iplot (figure_or_data , show_link = True , link_text = 'Export to plot.ly' ,
236
265
validate = True , image = None , filename = 'plot_image' , image_width = 800 ,
237
266
image_height = 600 ):
@@ -301,10 +330,10 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
301
330
)
302
331
# if image is given, and is a valid format, we will download the image
303
332
script = get_image_download_script ('iplot' ).format (format = image ,
304
- width = image_width ,
305
- height = image_height ,
306
- filename = filename ,
307
- plot_id = plotdivid )
333
+ width = image_width ,
334
+ height = image_height ,
335
+ filename = filename ,
336
+ plot_id = plotdivid )
308
337
# allow time for the plot to draw
309
338
time .sleep (1 )
310
339
# inject code to download an image of the plot
0 commit comments