'Plotly dash export image with annotations in Python

I am basically trying to export an image that I annotated in dash by using plotly to a jpg without whitespaces legends, x axis, y axis etc.

I have found a workaround but I am not very happy with it. Workaround that I found is that by removing legends, margins, x axis and y axis and by giving hardcoded height and width such as

fig.update_layout(showlegend=False, height=256, width=256, margin={'l': 0, 'r': 0, 't': 0, 'b': 0})

fig.update_xaxes(visible=False)

fig.update_yaxes(visible=False)

And using

figure.write_image()

to save it.

I do not like to use the workaround since it:

  • removes everything such as legends, x axis, y axis etc
  • doesn't autoscale
  • Doesn't look good without margins and everything


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source