offline.plot
方法具有image='png
和image_filename='image_file_name'
属性,可将文件另存为png
。
offline.plot({'data': [{'y': [4, 2, 3, 4]}],
'layout': {'title': 'Test Plot',
'font': dict(family='Comic Sans MS', size=16)}},
auto_open=True, image = 'png', image_filename='plot_image',
output_type='file', image_width=800, image_height=600,
filename='temp-plot.html', validate=False)
在上offline.py
或在线查看更多详细信息plotly
。
但是,有一点需要注意的是,由于输出图像是与HTML绑定的,因此它将在浏览器中打开,并要求获得保存图像文件的权限。您可以在浏览器设置中将其关闭。
或者,您可能希望使用查看从plotly到matplotlib的转换plot_mpl
。 以下示例来自offline.py
from plotly.offline import init_notebook_mode, plot_mpl
import matplotlib.pyplot as plt
init_notebook_mode()
fig = plt.figure()
x = [10, 15, 20, 25, 30]
y = [100, 250, 200, 150, 300]
plt.plot(x, y, "o")
plot_mpl(fig)
# If you want to to download an image of the figure as well
plot_mpl(fig, image='png')