2

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
  • You could create a copy of the figure and then apply the workaround so that the original figure isn't modified, but if you want to extract only part of the figure, I think you'll need to use your workaround to remove extraneous parts of your figure – Derek O Apr 26 '22 at 19:48
  • There are some things I do not understand here. You removed the axes, and then state that you do not like the workaround because the axes are removed. Why did you remove the axes, etc ? Can you just create the figure with plotly (not dash) and then save the figures using the methods available from plotly, such as fig.write_html(output_fpath) ? – bici.sancta Apr 26 '22 at 20:32
  • Is this question useful for your problem : https://stackoverflow.com/questions/59815797/how-to-save-plotly-express-plot-into-a-html-or-static-image-file ? – bici.sancta Apr 26 '22 at 20:42
  • @bici.sancta When I save it with axes then it will be in the jpg file created. I do not want those in the jpg files I created. Also that question does not solve my problem – asdasd asdasd Apr 27 '22 at 00:21
  • I honestly do not understand what you are trying to achieve. Your statements sound completely self-contradictory. A : "I am trying to export an image without legends", B : "I have a workaround that removes legends", C : "I do not like the workaround since it removes the legends". A & C are contradictory statements. – bici.sancta Apr 27 '22 at 01:37
  • I think I made it clear already but, I want to have a figure in dash with legends, axises etc... but in backend I want to save it with only image and annotations not legends etc. – asdasd asdasd Apr 27 '22 at 03:50

0 Answers0