Im trying to figure out how I can change size of the image in my Plotly saved image.. right now the size is small but i would like to change it so that its better to see details.
You can use the scale parameter to increase the resolution of the image, e.g. fig. write_image("fig_name. png", scale=5) , see the Plotly documentation for more details.
Set automargin to True and Plotly will automatically increase the margin size to prevent ticklabels from being cut off or overlapping with axis titles.
Figures made with Plotly Express can be customized in all the same ways as figures made with graph objects, as well as with PX-specific function arguments. New to Plotly? Plotly is a free and open-source graphing library for Python.
In order to export your figure as your desired image file format, at the resolution you specified for your figure, you can use the plotly.io.write_image
function.
Example from the link below, the documentation (where fig is your image, and you want a .PNG):
import plotly.io as pio
pio.write_image(fig, 'images/fig1.png')
This also works for .JPEG, .WebP and even vector formats .SVG, .PDF and .EPS. Just replace .PNG with what you need.
https://plot.ly/python/static-image-export/
As further response: to get the precise size you want, you can change your layout to include the following (where fig is your figure):
layout = go.Layout(
autosize=False,
width=500,
height=500
)
fig = go.Figure(data=data, layout=layout)
pio.write_image(fig, 'images/fig1.png')
from: https://plot.ly/python/setting-graph-size/ This should let you give the image whatever dimensions you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With