Controlling 'snapshot' output resolution in a Dash app

The plots saved with the ‘download plot as png’/‘snapshot’ button are usually exported with really poor resolution and seem to scale with the viewport.

I’m referring to the button you see in the image, NOT to the static export option.

Is there any way to control the resolution or the size of the PNGs created with this option?

@guidocioni ,

As far as I know, that is not possible using python.
referring by this link

The option available is using static export option, but combine with custom download button on Dash app. Also you need to hide the Download plot as a png from modebar as well.

If you interested, I can provide an example.

Mmm ok I see, however I feel there must be a place where the DPI or the size of the screenshot is hard coded…no?

Hi @guidocioni ,

I found how to resize the downloaded image in Plotly docs.
This is maybe what you need.

this code is an example from link above.

import plotly.express as px

config = {
  'toImageButtonOptions': {
    'format': 'svg', # one of png, svg, jpeg, webp
    'filename': 'custom_image',
    'height': 500,
    'width': 700,
    'scale': 1 # Multiply title/legend/axis/canvas sizes by this factor
  }
}

fig = px.bar(x=[1, 2, 3], y=[1, 3, 1])

fig.show(config=config)

hope this help.

Yes, finally! thank you, I don’t know how I didn’t find that page

1 Like