Saving WebGl plots to svg file

Hi all,

I am using plotly express and graph_objects to make plots I want to display and save to file. Some of these plots have a lot of point so I would like to keep them as webGl plots during rendering.

However, when exporting these to .svg I would like to have them as vectors to avoid the blurryness described here: Blurry image while using plotly express

Basically I need render mode to be ‘webgl’ for display and ‘svg’ for saving. I am able to do it with this solution:


# create fig and show
fig = px.line(df, x='x', y='y')
fig.show()

# save as svg
dt = fig.to_dict()
dt['data'][0]['type']  ='scatter' # change from 'scattergl'
write_image(dt, "test.svg")

This seems very hacky though. Is there a better way? I think an optional kwarg for render_mode in write_image() would be a big boon.