Bre*_*ser 10
为了将您的图形导出为所需的图像文件格式,在您为图形指定的分辨率下,您可以使用该plotly.io.write_image功能。
以下链接中的示例,文档(其中 fig 是您的图像,并且您想要一个 .PNG):
import plotly.io as pio
pio.write_image(fig, 'images/fig1.png')
Run Code Online (Sandbox Code Playgroud)
这也适用于 .JPEG、.WebP 甚至矢量格式 .SVG、.PDF 和 .EPS。只需将 .PNG 替换为您需要的即可。
https://plot.ly/python/static-image-export/
作为进一步的回应:为了获得您想要的精确尺寸,您可以更改您的布局以包括以下内容(其中 fig 是您的数字):
layout = go.Layout(
autosize=False,
width=500,
height=500
)
fig = go.Figure(data=data, layout=layout)
pio.write_image(fig, 'images/fig1.png')
Run Code Online (Sandbox Code Playgroud)
来自:https : //plot.ly/python/setting-graph-size/ 这应该让你给图像任何你想要的尺寸。
小智 10
You can specify the height and width when saving the file and increase the scale size for better quality.
import plotly.io as pio
pio.write_image(fig, file, format=png/jpeg/svg, scale=1, width=1000, height=800)
Run Code Online (Sandbox Code Playgroud)
恕我直言,还有一种更简单的方法来定义保存图像的宽度和高度,只需将值添加到 write_image 方法中的参数 width 和 height 中,如下所示:
import plotly.io as pio
pio.write_image(fig, 'yourImage.png', width=1980, height=1080)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7590 次 |
| 最近记录: |