Plotly Save as SVG button

Default plotly toolbar has download as png option. In order to save your graph as svg, below configuration is working on graph object which is default available in plotly express but not mentioned or documented in graph objects.

Python configuration options documentation page: https://plotly.com/python/configuration-options/

Javascript configuration options documentation page: https://plotly.com/javascript/configuration-options/

import plotly.express as px

config = {
  'toImageButtonOptions': {
    'format': 'svg', # one of png, svg, jpeg, webp
    'filename': 'custom_image',
    'height': 500,
    'width': 700,
    'scale': 1 # Multiply title/legend/axis/canvas sizes by this factor
  }
}

fig = px.bar(x=[1, 2, 3], y=[1, 3, 1])

fig.show(config=config)

same config works for graph objects too. If you dont want to show with fig.show like me, fig.write_html accept config parameter.

fig11.write_html("./name.html", include_plotlyjs="cdn", full_html=True, config=config)

Also if you dont specify the height width scale etc. current screen is saved as is.

config = {
        'toImageButtonOptions': {
            'format': 'svg'
        }
    }

Now download plot button download plots as svg.

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

2 + eight =