def go_offline(connected=False):
"""Take plotting offline.
__PLOTLY_OFFLINE_INITIALIZED is a secret variable
in plotly/offline/offline.py.
Parameters
---------
connected : bool
Determines if init_notebook_mode should be set to 'connected'.
99% of time will not need to touch this.
"""
try:
pyo.init_notebook_mode(connected)
except TypeError:
pyo.init_notebook_mode()
pyo.__PLOTLY_OFFLINE_INITIALIZED = True
python类offline()的实例源码
def check_url(url=None):
"""Check URL integrity.
Parameters
----------
url : string
URL to be checked.
"""
if url is None:
if 'http' not in get_config_file()['offline_url']:
raise Exception("No default offline URL set. "
"Please run "
"quantmod.set_config_file(offline_url=YOUR_URL) "
"to set the default offline URL.")
else:
url = get_config_file()['offline_url']
if url is not None:
if not isinstance(url, six.string_types):
raise TypeError("Invalid url '{0}'. "
"It should be string."
.format(url))
pyo.download_plotlyjs(url)
def plotVAEplotly(self, logdir, prefix, ctable=None, reverseUtt=False, batch_size=128, debug=False):
ticks = [[-1,-0.5,0,0.5,1]]*self.latentDim
samplePoints = np.array(np.meshgrid(*ticks)).T.reshape(-1,3)
input_placeholder = np.ones(tuple([len(samplePoints)] + list(self.phon.output_shape[1:-1]) + [1]))
preds = self.decode_word([samplePoints, input_placeholder], batch_size=batch_size)
if reverseUtt:
preds = getYae(preds, reverseUtt)
reconstructed = reconstructXae(np.expand_dims(preds.argmax(-1), -1), ctable, maxLen=5)
data = [go.Scatter3d(
x = samplePoints[:,0],
y = samplePoints[:,1],
z = samplePoints[:,2],
text = reconstructed,
mode='text'
)]
layout = go.Layout()
fig = go.Figure(data=data, layout=layout)
plotly.offline.plot(fig, filename=logdir + '/' + prefix + '_VAEplot.html', auto_open=False)
def plot(self, figure_or_data) -> None:
self.buffer.append(
plotly.offline.plot(figure_or_data, show_link=False,
validate=True, output_type='div',
include_plotlyjs=False)
)
PlotlyPlotter._first = False
def get_plotlyjs():
path = os.path.join('offline', 'plotly.min.js')
plotlyjs = resource_string('plotly', path).decode('utf-8')
return plotlyjs
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))
```
def go_online():
"""Take plotting offline."""
pyo.__PLOTLY_OFFLINE_INITIALIZED = False
def is_offline():
"""Check online/offline status."""
return pyo.__PLOTLY_OFFLINE_INITIALIZED
def get_plotlyjs():
path = os.path.join('offline', 'plotly.min.js')
plotlyjs = resource_string('plotly', path).decode('utf-8')
return plotlyjs
def get_version_one_path() -> typing.Union[str, None]:
try:
from plotly.offline import offline as plotly_offline
except Exception:
return None
return os.path.join(
environ.paths.clean(os.path.dirname(plotly_offline.__file__)),
'plotly.min.js'
)