@@ -273,7 +273,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
273
273
validate = True , image = None , filename = 'plot_image' , image_width = 800 ,
274
274
image_height = 600 ):
275
275
"""
276
- Draw plotly graphs inside an IPython notebook without
276
+ Draw plotly graphs inside an IPython or Jupter notebook without
277
277
connecting to an external server.
278
278
To save the chart to Plotly Cloud or Plotly Enterprise, use
279
279
`plotly.plotly.iplot`.
@@ -335,7 +335,33 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
335
335
figure_or_data , config , validate , '100%' , 525 , True
336
336
)
337
337
338
- ipython_display .display (ipython_display .HTML (plot_html ))
338
+ figure = tools .return_figure_from_figure_or_data (figure_or_data , validate )
339
+
340
+ # Display 2 versions of the figure:
341
+ # - The raw HTML is the "old-school" style - we just throw in a JS script
342
+ # inside the cell. This works for a lot of environments but some JS is
343
+ # stripped out in some rendering environments / platforms like
344
+ # GitHub, nteract, and eventually Plotly
345
+ # - The custom `mime-types` is the new-school way. nteract supports
346
+ # rendering plotly graphs this way (see https://github.com/nteract/nteract/pull/662)
347
+ # and others will hopefully follow suite.
348
+ # Both of these bundles will be saved as part of the notebook. The renderer
349
+ # will choose which one to render. So 'text/html' is like a fallback for
350
+ # any environment that doesn't have the 'application/json+plotly.v1'
351
+ # renderer available.
352
+ # The bummer is that we're injecting the figure JSON in here twice, so
353
+ # notebooks that are pretty big are about to get a lot bigger.
354
+ # The upside is that we're dropping any compatability for older notebook
355
+ # versions
356
+ data = _json .loads (_json .dumps (figure ['data' ],
357
+ cls = plotly .utils .PlotlyJSONEncoder ))
358
+ layout = _json .loads (_json .dumps (figure .get ('layout' , {}),
359
+ cls = plotly .utils .PlotlyJSONEncoder ))
360
+ display_bundle = {
361
+ 'application/vnd.plotly.v1+json' : {'data' : data , 'layout' : layout },
362
+ 'text/html' : plot_html
363
+ }
364
+ ipython_display .display (display_bundle , raw = True )
339
365
340
366
if image :
341
367
if image not in __IMAGE_FORMATS :
0 commit comments