@@ -312,30 +312,52 @@ def plot(figure_or_data,
312312
313313
314314def plot_mpl (mpl_fig , resize = False , strip_style = False ,
315- verbose = False , ** kwargs ):
316- '''
317- Convert a matplotlib figure to a plotly graph locally as an HTML document
318- or string
315+ verbose = False , show_link = True , link_text = 'Export to plot.ly' ,
316+ validate = True , output_type = 'file' , include_plotlyjs = True ,
317+ filename = 'temp-plot.html' , auto_open = True ):
318+ """
319+ Convert a matplotlib figure to a Plotly graph stored locally as HTML.
319320
320321 For more information on converting matplotlib visualizations to plotly
321- graphs, call help(plotly.tools.mpl_to_plotly )
322+ graphs, call help(plotly.plot_mpl )
322323
323324 For more information on creating plotly charts locally as an HTML document
324325 or string, call help(plotly.offline.plot)
325326
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)`
327+ mpl_fig -- a matplotlib figure object to convert to a plotly graph
328+
329+ Keyword arguments:
330+ resize (default=False) -- allow plotly to choose the figure size.
331+ strip_style (default=False) -- allow plotly to choose style options.
332+ verbose (default=False) -- print message.
333+ show_link (default=True) -- display a link in the bottom-right corner of
334+ of the chart that will export the chart to Plotly Cloud or
335+ Plotly Enterprise
336+ link_text (default='Export to plot.ly') -- the text of export link
337+ validate (default=True) -- validate that all of the keys in the figure
338+ are valid? omit if your version of plotly.js has become outdated
339+ with your version of graph_reference.json or if you need to include
340+ extra, unnecessary keys in your figure.
341+ output_type ('file' | 'div' - default 'file') -- if 'file', then
342+ the graph is saved as a standalone HTML file and `plot`
343+ returns None.
344+ If 'div', then `plot` returns a string that just contains the
345+ HTML <div> that contains the graph and the script to generate the
346+ graph.
347+ Use 'file' if you want to save and view a single graph at a time
348+ in a standalone HTML file.
349+ Use 'div' if you are embedding these graphs in an HTML file with
350+ other graphs or HTML markup, like a HTML report or an website.
351+ include_plotlyjs (default=True) -- If True, include the plotly.js
352+ source code in the output file or string.
353+ Set as False if your HTML file already contains a copy of the plotly.js
354+ library.
355+ filename (default='temp-plot.html') -- The local filename to save the
356+ outputted chart to. If the filename already exists, it will be
357+ overwritten. This argument only applies if `output_type` is 'file'.
358+ auto_open (default=True) -- If True, open the saved file in a
359+ web browser after saving.
360+ This argument only applies if `output_type` is 'file'.
339361
340362 Example:
341363 ```
@@ -351,14 +373,16 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False,
351373
352374 plot_mpl(fig)
353375 ```
354- '''
376+ """
355377 plotly_plot = tools .mpl_to_plotly (mpl_fig , resize , strip_style , verbose )
356- return plot (plotly_plot , ** kwargs )
378+ return plot (plotly_plot , show_link , link_text , validate , output_type ,
379+ include_plotlyjs , filename , auto_open )
357380
358381
359382def iplot_mpl (mpl_fig , resize = False , strip_style = False ,
360- verbose = False , ** kwargs ):
361- '''
383+ verbose = False , show_link = True ,
384+ link_text = 'Export to plot.ly' , validate = True ):
385+ """
362386 Convert a matplotlib figure to a plotly graph and plot inside an IPython
363387 notebook without connecting to an external server.
364388
@@ -371,14 +395,24 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False,
371395 For more information on plotting plotly charts offline in an Ipython
372396 notebook call `help(plotly.offline.iplot)`
373397
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
398+ mpl_fig -- a matplotlib.figure to convert to a plotly graph
399+
400+ Keyword arguments:
401+ resize (default=False) -- allow plotly to choose the figure size.
402+ strip_style (default=False) -- allow plotly to choose style options.
403+ verbose (default=False) -- print message.
404+ show_link (default=True) -- display a link in the bottom-right corner of
405+ of the chart that will export the chart to Plotly Cloud or
406+ Plotly Enterprise
407+ show_link (default=True) -- display a link in the bottom-right corner of
408+ of the chart that will export the chart to
409+ Plotly Cloud or Plotly Enterprise
410+ link_text (default='Export to plot.ly') -- the text of export link
411+ validate (default=True) -- validate that all of the keys in the figure
412+ are valid? omit if your version of plotly.js
413+ has become outdated with your version of
414+ graph_reference.json or if you need to include
415+ extra, unnecessary keys in your figure.
382416
383417 Example:
384418 ```
@@ -394,17 +428,18 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False,
394428
395429 iplot_mpl(fig)
396430 ```
397- '''
431+ """
398432 plotly_plot = tools .mpl_to_plotly (mpl_fig , resize , strip_style , verbose )
399- return iplot (plotly_plot , ** kwargs )
433+ return iplot (plotly_plot , show_link , link_text , validate )
400434
401435
402- def plotly_takeover (** kwargs ):
403- '''
404- Enable the automatic matplotlib to plotly conversion and display
405- of figures in an IPython Notebook.
436+ def enable_mpl_offline (resize = False , strip_style = False ,
437+ verbose = False , show_link = True ,
438+ link_text = 'Export to plot.ly' , validate = True ):
439+ """
440+ Convert mpl plots to locally hosted HTML documents.
406441
407- This function should be used with the inline Matplotlib backend
442+ This function should be used with the inline matplotlib backend
408443 that ships with IPython that can be enabled with `%pylab inline`
409444 or `%matplotlib inline`. This works by adding an HTML formatter
410445 for Figure objects; the existing SVG/PNG formatters will remain
@@ -417,7 +452,7 @@ def plotly_takeover(**kwargs):
417452 from plotly.offline import init_notebook_mode, plotly_takeover
418453 import matplotlib.pyplot as plt
419454
420- init_notebook_mode
455+ init_notebook_mode()
421456 plotly_takeover()
422457
423458 fig = plt.figure()
@@ -426,11 +461,12 @@ def plotly_takeover(**kwargs):
426461 plt.plot(x, y, "o")
427462 fig
428463 ```
429- '''
464+ """
430465 if not __PLOTLY_OFFLINE_INITIALIZED :
431466 init_notebook_mode ()
432467 ip = IPython .core .getipython .get_ipython ()
433468 formatter = ip .display_formatter .formatters ['text/html' ]
434469 formatter .for_type (matplotlib .figure .Figure ,
435- lambda fig , kwds = kwargs : iplot_mpl (fig , ** kwds ))
470+ lambda fig : iplot_mpl (fig , resize , strip_style , verbose ,
471+ show_link , link_text , validate ))
436472
0 commit comments