Black Lives Matter. Please consider donating to Black Girls Code today.

Download plot as png

I’ve created a visualization that is broken up into a 5x3 grid of subplots. I’m able to get this to display properly by specifying a larger height via the layout. The issue is that when I use the “download as png” function, that it exports the image with the default height, not the new height. The result is a figure that’s completely illegible and squished.

Not sure if this is relevant, but I’m generating the plots using add_trace and changing the layout with update_layout methods.

Thanks so much!

Hi @jmillz, your issue is related to Turn off Autoscaling for Bar Graph Text AND not matching the download scale (See replies) I think, you need to do{toImageButtonOptions: {width: null, height: null}}) in order to force the download-to-png button to follow the figure dimensions (otherwise it’s using fixed dimensions).

I was able to get the code to work as a plotly graph in jupyter with slight modification for Python:{‘toImageButtonOptions’: {‘width’: None,‘height’: None}})

However, for my application in Dash the code does not work. I’m populating the graph in a callback by returning my populated “fig” variable as an output. Just adding the line above to the callback before the return doesn’t seem to work. Maybe the command doesn’t really make sense for a graph that’s displayed outside of the function call?

For a Dash app, the dcc.Graph has a config attribute, so you can pass the above config dictionary to dcc.Graph instead of Indeed, should not be called in a Dash app.

Okay that worked for me. Thanks so much!