@@ -322,26 +322,13 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
322322 iplot([{'x': [1, 2, 3], 'y': [5, 2, 7]}], image='png')
323323 ```
324324 """
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- ]))
334325 if not ipython :
335326 raise ImportError ('`iplot` can only run inside an IPython Notebook.' )
336327
337328 config = dict (config ) if config else {}
338329 config .setdefault ('showLink' , show_link )
339330 config .setdefault ('linkText' , link_text )
340331
341- plot_html , plotdivid , width , height = _plot_html (
342- figure_or_data , config , validate , '100%' , 525 , True
343- )
344-
345332 figure = tools .return_figure_from_figure_or_data (figure_or_data , validate )
346333
347334 # 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',
358345 if frames :
359346 fig ['frames' ] = frames
360347
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+
366357 ipython_display .display (display_bundle , raw = True )
367358
368359 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+ ]))
369369 if image not in __IMAGE_FORMATS :
370370 raise ValueError ('The image parameter must be one of the following'
371371 ': {}' .format (__IMAGE_FORMATS )
0 commit comments