Image export, how to set DPI ? Alternatively, how to scale down using width and height?

What is the standard DPI when exporting as .svg using the standard write_image function?

I generally encounter problems when downsizing my graphs using both write_image or if defined by update_layout. Eg. If I need to make a figure of lets say 400 x 200 pixels, the graph annotations are not downsized and the resultant graph is a big mess

1 Like

@mikkelc

You can set dpi, as well as the width and height, of your figure to be saved, as follows:

import plotly.io as pio
#save a figure of 300dpi, with 1.5 inches, and  height 0.75inches
pio.write_image(fig, "test.svg", width=1.5*300, height=0.75*300, scale=1)

With these settings you’ll get the svg file (pdf or eps, as well) of expected size. If you want to further downsize the resulted image, you can set scale<1. It also downsizes the fonts.

2 Likes

Thank you very much, this works!