Convert mpl plots to locally hosted HTML documents. This function should be used with the inline matplotlib backend that ships with IPython that can be enabled with `%pylab inline` or `%matplotlib inline`. This works by adding an HTML formatter for Figure objects; the existing
(
resize=False,
strip_style=False,
verbose=False,
show_link=False,
link_text="Export to plot.ly",
validate=True,
)
| 792 | |
| 793 | |
| 794 | def enable_mpl_offline( |
| 795 | resize=False, |
| 796 | strip_style=False, |
| 797 | verbose=False, |
| 798 | show_link=False, |
| 799 | link_text="Export to plot.ly", |
| 800 | validate=True, |
| 801 | ): |
| 802 | """ |
| 803 | Convert mpl plots to locally hosted HTML documents. |
| 804 | |
| 805 | This function should be used with the inline matplotlib backend |
| 806 | that ships with IPython that can be enabled with `%pylab inline` |
| 807 | or `%matplotlib inline`. This works by adding an HTML formatter |
| 808 | for Figure objects; the existing SVG/PNG formatters will remain |
| 809 | enabled. |
| 810 | |
| 811 | (idea taken from `mpld3._display.enable_notebook`) |
| 812 | |
| 813 | Example: |
| 814 | ``` |
| 815 | from plotly.offline import enable_mpl_offline |
| 816 | import matplotlib.pyplot as plt |
| 817 | |
| 818 | enable_mpl_offline() |
| 819 | |
| 820 | fig = plt.figure() |
| 821 | x = [10, 15, 20, 25, 30] |
| 822 | y = [100, 250, 200, 150, 300] |
| 823 | plt.plot(x, y, "o") |
| 824 | fig |
| 825 | ``` |
| 826 | """ |
| 827 | init_notebook_mode() |
| 828 | ipython = get_module("IPython") |
| 829 | matplotlib = get_module("matplotlib") |
| 830 | |
| 831 | ip = ipython.core.getipython.get_ipython() |
| 832 | formatter = ip.display_formatter.formatters["text/html"] |
| 833 | formatter.for_type( |
| 834 | matplotlib.figure.Figure, |
| 835 | lambda fig: iplot_mpl( |
| 836 | fig, resize, strip_style, verbose, show_link, link_text, validate |
| 837 | ), |
| 838 | ) |
nothing calls this directly
no test coverage detected