plotly.io.to_image

plotly.io.to_image(fig, format=None, width=None, height=None, scale=None, validate=True)

Convert a figure to a static image bytes string

Parameters
  • fig – Figure object or dict representing a figure

  • format (str or None) –

    The desired image format. One of
    • ’png’

    • ’jpg’ or ‘jpeg’

    • ’webp’

    • ’svg’

    • ’pdf’

    • ’eps’ (Requires the poppler library to be installed)

    If not specified, will default to plotly.io.config.default_format

  • width (int or None) –

    The width of the exported image in layout pixels. If the scale property is 1.0, this will also be the width of the exported image in physical pixels.

    If not specified, will default to plotly.io.config.default_width

  • height (int or None) –

    The height of the exported image in layout pixels. If the scale property is 1.0, this will also be the height of the exported image in physical pixels.

    If not specified, will default to plotly.io.config.default_height

  • scale (int or float or None) –

    The scale factor to use when exporting the figure. A scale factor larger than 1.0 will increase the image resolution with respect to the figure’s layout pixel dimensions. Whereas as scale factor of less than 1.0 will decrease the image resolution.

    If not specified, will default to plotly.io.config.default_scale

  • validate (bool) – True if the figure should be validated before being converted to an image, False otherwise.

Returns

The image data

Return type

bytes