我有一些matplotlib图需要在浏览器中离线查看,我以前使用MPLD3进行渲染,但是由于需要在没有Internet连接的情况下查看图,因此我正在考虑使用plotly。有没有办法离线查看matplotlib绘图图?
答案 0 :(得分:1)
第Offline Use
节的this page怎么样
顺便说一句:您也可以按照here
的描述编写静态图像文件。import plotly.io as pio
import plotly.graph_objs as go
fig = go.Figure()
# Do some fig.add_scatter() stuff here
pio.write_image(fig, 'fig1.png')
答案 1 :(得分:0)
最小化将matplotlib图形转换为可绘制的样子。
import matplotlib.pyplot as plt
import plotly
import plotly.plotly as py
import plotly.tools as tls
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [1, 4, 9], "o")
plotly_fig = tls.mpl_to_plotly(fig)
plotly.offline.plot(plotly_fig, filename="plotly version of an mpl figure")
仅将其发布为文档文档有点困难。
答案 2 :(得分:0)
import plotly.tools as tls
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
x = np.random.random(100) ### toy data
y = np.random.random(100) ### toy data
## matplotlib fig
fig, axes = plt.subplots(2,1, figsize = (10,6))
axes[0].plot(x, label = 'x')
axes[1].scatter(x,y)
## convert and plot in plotly
plotly_fig = tls.mpl_to_plotly(fig) ## convert
iplot(plotly_fig)