@@ -322,26 +322,13 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
322
322
iplot([{'x': [1, 2, 3], 'y': [5, 2, 7]}], image='png')
323
323
```
324
324
"""
325
- if not __PLOTLY_OFFLINE_INITIALIZED :
326
- raise PlotlyError ('\n ' .join ([
327
- 'Plotly Offline mode has not been initialized in this notebook. '
328
- 'Run: ' ,
329
- '' ,
330
- 'import plotly' ,
331
- 'plotly.offline.init_notebook_mode() '
332
- '# run at the start of every ipython notebook' ,
333
- ]))
334
325
if not ipython :
335
326
raise ImportError ('`iplot` can only run inside an IPython Notebook.' )
336
327
337
328
config = dict (config ) if config else {}
338
329
config .setdefault ('showLink' , show_link )
339
330
config .setdefault ('linkText' , link_text )
340
331
341
- plot_html , plotdivid , width , height = _plot_html (
342
- figure_or_data , config , validate , '100%' , 525 , True
343
- )
344
-
345
332
figure = tools .return_figure_from_figure_or_data (figure_or_data , validate )
346
333
347
334
# Though it can add quite a bit to the display-bundle size, we include
@@ -358,14 +345,27 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
358
345
if frames :
359
346
fig ['frames' ] = frames
360
347
361
- display_bundle = {
362
- 'application/vnd.plotly.v1+json' : fig ,
363
- 'text/html' : plot_html ,
364
- 'text/vnd.plotly.v1+html' : plot_html
365
- }
348
+ display_bundle = {'application/vnd.plotly.v1+json' : fig }
349
+
350
+ if __PLOTLY_OFFLINE_INITIALIZED :
351
+ plot_html , plotdivid , width , height = _plot_html (
352
+ figure_or_data , config , validate , '100%' , 525 , True
353
+ )
354
+ display_bundle ['text/html' ] = plot_html
355
+ display_bundle ['text/vnd.plotly.v1+html' ] = plot_html
356
+
366
357
ipython_display .display (display_bundle , raw = True )
367
358
368
359
if image :
360
+ if not __PLOTLY_OFFLINE_INITIALIZED :
361
+ raise PlotlyError ('\n ' .join ([
362
+ 'Plotly Offline mode has not been initialized in this notebook. '
363
+ 'Run: ' ,
364
+ '' ,
365
+ 'import plotly' ,
366
+ 'plotly.offline.init_notebook_mode() '
367
+ '# run at the start of every ipython notebook' ,
368
+ ]))
369
369
if image not in __IMAGE_FORMATS :
370
370
raise ValueError ('The image parameter must be one of the following'
371
371
': {}' .format (__IMAGE_FORMATS )
0 commit comments