本文整理汇总了Python中plotly.offline.init_notebook_mode方法的典型用法代码示例。如果您正苦于以下问题:Python offline.init_notebook_mode方法的具体用法?Python offline.init_notebook_mode怎么用?Python offline.init_notebook_mode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plotly.offline
的用法示例。
在下文中一共展示了offline.init_notebook_mode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _render
# 需要导入模块: from plotly import offline [as 别名]
# 或者: from plotly.offline import init_notebook_mode [as 别名]
def _render(fig, showlegend=None):
"""Plot a matploltib or plotly figure"""
if isinstance(fig, plt.Figure):
fig = plotly.tools.mpl_to_plotly(fig, **PLOTLY_TO_MPL_KWS)
if showlegend is not None:
fig.layout["showlegend"] = showlegend
if not IN_NOTEBOOK:
message = "Lens explorer can only plot in a Jupyter notebook"
logger.error(message)
raise ValueError(message)
else:
if not py.offline.__PLOTLY_OFFLINE_INITIALIZED:
py.init_notebook_mode()
return py.iplot(fig, **PLOTLY_KWS)
示例2: save_wordmesh_as_html
# 需要导入模块: from plotly import offline [as 别名]
# 或者: from plotly.offline import init_notebook_mode [as 别名]
def save_wordmesh_as_html(self, coordinates, filename='temp-plot.html',
animate=False, autozoom=True, notebook_mode=False):
zoom = 1
labels = ['default label']
traces = []
if animate:
for i in range(coordinates.shape[0]):
traces.append(self._get_trace(coordinates[i]))
labels = list(map(str,range(coordinates.shape[0])))
else:
if autozoom:
zoom = self._get_zoom(coordinates)
traces = [self._get_trace(coordinates, zoom=zoom)]
layout = self._get_layout(labels, zoom=zoom)
fig = self.generate_figure(traces, labels, layout)
if notebook_mode:
py.init_notebook_mode(connected=True)
py.iplot(fig, filename=filename, show_link=False)
else:
py.plot(fig, filename=filename, auto_open=False, show_link=False)
示例3: enable_mpl_offline
# 需要导入模块: from plotly import offline [as 别名]
# 或者: from plotly.offline import init_notebook_mode [as 别名]
def enable_mpl_offline(resize=False, strip_style=False,
verbose=False, show_link=True,
link_text='Export to plot.ly', validate=True):
"""
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 SVG/PNG formatters will remain
enabled.
(idea taken from `mpld3._display.enable_notebook`)
Example:
```
from plotly.offline import enable_mpl_offline
import matplotlib.pyplot as plt
enable_mpl_offline()
fig = plt.figure()
x = [10, 15, 20, 25, 30]
y = [100, 250, 200, 150, 300]
plt.plot(x, y, "o")
fig
```
"""
init_notebook_mode()
ip = IPython.core.getipython.get_ipython()
formatter = ip.display_formatter.formatters['text/html']
formatter.for_type(matplotlib.figure.Figure,
lambda fig: iplot_mpl(fig, resize, strip_style, verbose,
show_link, link_text, validate))
示例4: showTrace
# 需要导入模块: from plotly import offline [as 别名]
# 或者: from plotly.offline import init_notebook_mode [as 别名]
def showTrace(trace, layout=None, title=None):
""" Wrapper around Plotly's offline .plot() function
Parameters
----------
trace : plotly_trace
Plotly generated trace to be displayed offline
layout : plotly.graph_objs.Layout, optional
Layout of plot to be displayed offline
title : str, optional
Title of plot to be displayed offline
# colorize : bool, optional
# Toggles bw / colored plot [Default: True]
Returns
-------
fig : plotly_fig_handle
JSON representation of generated figure
"""
if layout is None:
layout = go.Layout(
scene=dict(
xaxis=dict(range=[-1, 1]),
yaxis=dict(range=[-1, 1]),
zaxis=dict(range=[-1, 1]),
aspectmode='cube'
)
)
# Wrap trace in array if needed
if not isinstance(trace, list):
trace = [trace]
fig = go.Figure(
data=trace,
layout=layout
)
if title is not None:
fig.layout.update(title=title)
filename = f'{title}.html'
else:
try:
filename = f'{fig.layout.title}.html'
except TypeError:
filename = f'{current_time()}.html'
# if colorize:
# data[0].autocolorscale = False
# data[0].surfacecolor = [0, 0.5, 1]
if env_info() == 'jupyter_notebook':
plotly_off.init_notebook_mode()
plotly_off.iplot(fig)
else:
plotly_off.plot(fig, filename=filename)
return fig