-
-
Couldn't load subscription status.
- Fork 2.7k
V1.10.0 - Inject plotly.js into the output cell on every init_notebook_mode call
#469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| import plotly | ||
| from plotly import tools, utils | ||
| from plotly.exceptions import PlotlyError | ||
|
|
||
| try: | ||
| import IPython | ||
|
|
@@ -28,6 +29,7 @@ | |
| except ImportError: | ||
| _matplotlib_imported = False | ||
|
|
||
| __PLOTLY_OFFLINE_INITIALIZED = False | ||
|
|
||
| def download_plotlyjs(download_url): | ||
| warnings.warn(''' | ||
|
|
@@ -50,16 +52,11 @@ def init_notebook_mode(): | |
| yet. This is an idempotent method and can and should be called from any | ||
| offline methods that require plotly.js to be loaded into the notebook dom. | ||
| """ | ||
| warnings.warn(''' | ||
| `init_notebook_mode` is deprecated and will be removed in the | ||
| next release. Notebook mode is now automatically initialized when | ||
| notebook methods are invoked, so it is no | ||
| longer necessary to manually initialize. | ||
| ''', DeprecationWarning) | ||
|
|
||
| if not _ipython_imported: | ||
| raise ImportError('`iplot` can only run inside an IPython Notebook.') | ||
|
|
||
| global __PLOTLY_OFFLINE_INITIALIZED | ||
| # Inject plotly.js into the output cell | ||
|
||
| script_inject = ( | ||
| '' | ||
| '<script type=\'text/javascript\'>' | ||
|
|
@@ -68,14 +65,14 @@ def init_notebook_mode(): | |
| '{script}' | ||
| '}});' | ||
| 'require([\'plotly\'], function(Plotly) {{' | ||
| 'console.log(Plotly);' | ||
| 'window.Plotly = Plotly;' | ||
| '}});' | ||
| '}}' | ||
| '</script>' | ||
| '').format(script=get_plotlyjs()) | ||
|
|
||
| display(HTML(script_inject)) | ||
| __PLOTLY_OFFLINE_INITIALIZED = True | ||
|
|
||
|
|
||
| def _plot_html(figure_or_data, show_link, link_text, | ||
|
|
@@ -177,13 +174,22 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', | |
|
|
||
| Example: | ||
| ``` | ||
| from plotly.offline import iplot | ||
|
|
||
| from plotly.offline import init_notebook_mode, iplot | ||
| init_notebook_mode() | ||
| iplot([{'x': [1, 2, 3], 'y': [5, 2, 7]}]) | ||
| ``` | ||
| """ | ||
|
|
||
| init_notebook_mode() | ||
| if not __PLOTLY_OFFLINE_INITIALIZED: | ||
| raise PlotlyError('\n'.join([ | ||
| 'Plotly Offline mode has not been initialized in this notebook. ' | ||
| 'Run: ', | ||
| '', | ||
| 'import plotly', | ||
| 'plotly.offline.init_notebook_mode() ' | ||
| '# run at the start of every ipython notebook', | ||
| ])) | ||
| if not tools._ipython_imported: | ||
| raise ImportError('`iplot` can only run inside an IPython Notebook.') | ||
|
|
||
| plot_html, plotdivid, width, height = _plot_html( | ||
| figure_or_data, show_link, link_text, validate, | ||
|
|
@@ -415,19 +421,18 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False, | |
|
|
||
| Example: | ||
| ``` | ||
| from plotly.offline import iplot_mpl | ||
| from plotly.offline import init_notebook_mode, iplot_mpl | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| fig = plt.figure() | ||
| x = [10, 15, 20, 25, 30] | ||
| y = [100, 250, 200, 150, 300] | ||
| plt.plot(x, y, "o") | ||
|
|
||
| init_notebook_mode() | ||
| iplot_mpl(fig) | ||
| ``` | ||
| """ | ||
| init_notebook_mode() | ||
|
|
||
| plotly_plot = tools.mpl_to_plotly(mpl_fig, resize, strip_style, verbose) | ||
| return iplot(plotly_plot, show_link, link_text, validate) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = '1.9.13' | ||
| __version__ = '1.10.0' |