Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the image size of a Plotly saved image?

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.enter image description here

like image 689
THEoneANDonly Avatar asked Feb 28 '19 09:02

THEoneANDonly


People also ask

How can I save Plotly graphs in high quality?

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.

How can I increase my figure size in Plotly?

Set automargin to True and Plotly will automatically increase the margin size to prevent ticklabels from being cut off or overlapping with axis titles.

Is Plotly customizable?

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.


1 Answers

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.

like image 82
Brent Visser Avatar answered Sep 18 '22 01:09

Brent Visser