Search code examples
pythonimagegraphsizeplotly

How can I change the image size of a Plotly saved image?


Im trying to figure out how I can change size of the image in my Plotly saved image.. right now the size is small but i would like to change it so that its better to see details.enter image description here


Solution

  • In order to export your figure as your desired image file format, at the resolution you specified for your figure, you can use the plotly.io.write_image function.

    Example from the link below, the documentation (where fig is your image, and you want a .PNG):

    import plotly.io as pio
    pio.write_image(fig, 'images/fig1.png')
    
    

    This also works for .JPEG, .WebP and even vector formats .SVG, .PDF and .EPS. Just replace .PNG with what you need.

    https://plot.ly/python/static-image-export/

    As further response: to get the precise size you want, you can change your layout to include the following (where fig is your figure):

    layout = go.Layout(
        autosize=False,
        width=500,
        height=500
    )
    fig = go.Figure(data=data, layout=layout)
    pio.write_image(fig, 'images/fig1.png')
    
    

    from: https://plot.ly/python/setting-graph-size/ This should let you give the image whatever dimensions you want.