@@ -204,9 +204,7 @@ def plot(figure_or_data,
204
204
from plotly.offline import plot
205
205
import plotly.graph_objs as go
206
206
207
- plot([
208
- go.Scatter(x=[1, 2, 3], y=[3, 2 6])
209
- ], filename='my-graph.html')
207
+ plot([go.Scatter(x=[1, 2, 3], y=[3, 2, 6])], filename='my-graph.html')
210
208
```
211
209
More examples below.
212
210
@@ -313,27 +311,123 @@ def plot(figure_or_data,
313
311
return plot_html
314
312
315
313
316
- def iplot_mpl (mpl_fig ,mpl_to_plotly_kw = {},iplot_kw = {}):
314
+ def plot_mpl (mpl_fig , resize = False , strip_style = False ,
315
+ verbose = False , ** kwargs ):
317
316
'''
318
- Convert a matplotlib figure to plotly dictionary plot inside an
319
- IPython notebook without connecting to an external server.
317
+ Convert a matplotlib figure to a plotly graph locally as an HTML document
318
+ or string
319
+
320
+ For more information on converting matplotlib visualizations to plotly
321
+ graphs, call help(plotly.tools.mpl_to_plotly)
322
+
323
+ For more information on creating plotly charts locally as an HTML document
324
+ or string, call help(plotly.offline.plot)
325
+
326
+ :param (matplotlib figure) mpl_fig: matplotlib figure to convert to a
327
+ plotly graph
328
+ :param (bool) resize: Default = False
329
+ :param (bool) strip_style: Default = False
330
+ :param (bool) verbose: Default = False
331
+ :param kwargs: kwargs passed through `plotly.offline.plot`.
332
+ For more information on valid kwargs call `help(plotly.offline.plot)`
333
+ :return (None|string): if `output_type` is 'file' (default), then the graph
334
+ is saved as a standalone HTML file and `plot_mpl` returns None.
335
+ If `output_type` is 'div', then `plot` returns a string that contains
336
+ the HTML <div> that contains the graph and the script to generate the
337
+ graph. For more information about `output_type` call
338
+ `help(plotly.offline.plot)`
339
+
340
+ Example:
341
+ ```
342
+ from plotly.offline import init_notebook_mode, plot_mpl
343
+ import matplotlib.pyplot as plt
344
+
345
+ init_notebook_mode()
346
+
347
+ fig = plt.figure()
348
+ x = [10, 15, 20, 25, 30]
349
+ y = [100, 250, 200, 150, 300]
350
+ plt.plot(x, y, "o")
351
+
352
+ plot_mpl(fig)
353
+ ```
320
354
'''
321
- plotly_plot = tools .mpl_to_plotly (mpl_fig ,** mpl_to_plotly_kw )
322
- return iplot (plotly_plot ,** iplot_kw )
355
+ plotly_plot = tools .mpl_to_plotly (mpl_fig , resize , strip_style , verbose )
356
+ return plot (plotly_plot , ** kwargs )
357
+
358
+
359
+ def iplot_mpl (mpl_fig , resize = False , strip_style = False ,
360
+ verbose = False , ** kwargs ):
361
+ '''
362
+ Convert a matplotlib figure to a plotly graph and plot inside an IPython
363
+ notebook without connecting to an external server.
364
+
365
+ To save the chart to Plotly Cloud or Plotly Enterprise, use
366
+ `plotly.tools.mpl_to_plotly`.
367
+
368
+ For more information on converting matplotlib visualizations to plotly
369
+ graphs call `help(plotly.tools.mpl_to_plotly)`
370
+
371
+ For more information on plotting plotly charts offline in an Ipython
372
+ notebook call `help(plotly.offline.iplot)`
373
+
374
+ :param (matplotlib figure) mpl_fig: matplotlib figure to convert to a
375
+ plotly graph
376
+ :param (bool) resize: Default = False
377
+ :param (bool) strip_style: Default = False
378
+ :param (bool) verbose: Default = False
379
+ :param kwargs: kwargs passed through `plotly.offline.iplot`.
380
+ For more information on valid kwargs call `help(plotly.offline.iplot)`
381
+ :return: draws converted plotly figure in Ipython notebook
382
+
383
+ Example:
384
+ ```
385
+ from plotly.offline import init_notebook_mode, iplot_mpl
386
+ import matplotlib.pyplot as plt
387
+
388
+ init_notebook_mode()
389
+
390
+ fig = plt.figure()
391
+ x = [10, 15, 20, 25, 30]
392
+ y = [100, 250, 200, 150, 300]
393
+ plt.plot(x, y, "o")
394
+
395
+ iplot_mpl(fig)
396
+ ```
397
+ '''
398
+ plotly_plot = tools .mpl_to_plotly (mpl_fig , resize , strip_style , verbose )
399
+ return iplot (plotly_plot , ** kwargs )
323
400
324
401
325
402
def plotly_takeover (** kwargs ):
326
403
'''
327
- Enable the automatic display of figures in the IPython Notebook.
404
+ Enable the automatic matplotlib to plotly conversion and display
405
+ of figures in an IPython Notebook.
406
+
328
407
This function should be used with the inline Matplotlib backend
329
408
that ships with IPython that can be enabled with `%pylab inline`
330
409
or `%matplotlib inline`. This works by adding an HTML formatter
331
410
for Figure objects; the existing SVG/PNG formatters will remain
332
411
enabled.
333
412
334
413
(idea taken from `mpld3._display.enable_notebook`)
414
+
415
+ Example:
416
+ ```
417
+ from plotly.offline import init_notebook_mode, plotly_takeover
418
+ import matplotlib.pyplot as plt
419
+
420
+ init_notebook_mode
421
+ plotly_takeover()
422
+
423
+ fig = plt.figure()
424
+ x = [10, 15, 20, 25, 30]
425
+ y = [100, 250, 200, 150, 300]
426
+ plt.plot(x, y, "o")
427
+ fig
428
+ ```
335
429
'''
336
- if __PLOTLY_OFFLINE_INITIALIZED != True :
430
+ if not __PLOTLY_OFFLINE_INITIALIZED :
337
431
init_notebook_mode ()
338
432
ip = IPython .core .getipython .get_ipython ()
339
433
formatter = ip .display_formatter .formatters ['text/html' ]
0 commit comments