Export Image without Plotting

I have a plot with subplots that I export for PDF generation. That works great, but I also want images of the side plots on their own for this report. I hacked my way to this by plotting them separately in a hidden <div> and then exporting them, but I have 5 visible plots already and with those two, I end up having too many WebGL contexts on the page and even lose a context.

So, I think this is a long shot, but is there any way to make an image of a plot without actually plotting it in a <div>?

TIA!

Chiara

https://codepen.io/etpinard/pen/rJKQPX?editors=0010 might give you ideas.

A couple things to note:

  • Plotly.toImage now accepts (I think this hasn’t made its way in our docs yet) a {data: [], layout: {}} object as first argument. This does create a hidden <div> (i.e. a <div> that we don’t attach to document.body) for you,
  • Plotly.toImage purges (equivalent to Plotly.purge) things like WebGL contexts on completion, so you shouldn’t see those too many WebGL context warnings.

I hope this helps.

1 Like

:100: :100: :100::100: :100: :100:

Seriously thought that I was SOL on this one. Haha!

Let’s see how many times I can say thank you in a year.

Thank you! (I think this makes 3)

–Chiara

1 Like