Static Image Export in Python

Plotly allows you to save static images of your plots. Save the image to your local computer, or embed it inside your Jupyter notebooks as a static image.


Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Try Plotly Studio now.

This page demonstrates how to export interactive Plotly figures to static image formats like PNG, JPEG, SVG, and PDF. If you want to export Plotly figures to HTML to retain interactivity, see the Interactive HTML Export page

Install Dependencies

Kaleido

Static image generation requires Kaleido. Install Kaleido with pip:

$ pip install --upgrade kaleido

or with conda:

$ conda install -c conda-forge python-kaleido

It's also possible to generate static images using Orca, though support for Orca will be removed after September 2025. See the Orca Management page for more details.

Chrome

Kaleido uses Chrome for static image generation. Versions of Kaleido prior to v1 included Chrome as part of the Kaleido package. Kaleido v1 does not include Chrome; instead, it looks for a compatible version of Chrome (or Chromium) already installed on the machine on which it's running.

If you don't have Chrome installed, you can install it directly from Google following the instructions for your operating system.

Plotly also provides a CLI for installing Chrome from the command line.

Run plotly_get_chrome to install Chrome.

You can also install Chrome from Python using plotly.io.get_chrome()

import plotly.io as pio

pio.get_chrome()

See the Additional Information on Browsers with Kaleido section below for more details on browser compatibility for Kaleido.

Write Image to a File

Plotly figures have a write_image method to write a figure to a file. write_image supports PNG, JPEG, WebP, SVG, and PDF formats.

To export a figure using write_image, call write_image on the figure, and pass as an argument the filename where you want to save the figure. The file format is inferred from the extension:

Raster Formats

PNG

import plotly.express as px
data_canada = px.data.gapminder().query("country == 'Canada'")
fig = px.bar(data_canada, x='year', y='pop')
fig.write_image("fig1.png")

JPEG

...
fig.write_image("images/fig1.jpeg")

WebP

...
fig.write_image("images/fig1.webp")

Vector Formats

SVG

...
fig.write_image("images/fig1.svg")

PDF

...
fig.write_image("images/fig1.pdf")

EPS (Kaleido<1.0.0)

Kaleido versions earlier than 1.0.0 also support EPS (requires the poppler library). If using Kaleido v1 or later, we recommend PDF or SVG format.

...
fig.write_image("images/fig1.eps")

Note: Figures containing WebGL traces (i.e. of type scattergl, contourgl, scatter3d, surface, mesh3d, scatterpolargl, cone, streamtube, splom, or parcoords) that are exported in a vector format will include encapsulated rasters, instead of vectors, for some parts of the image.

Specify a Format

In the earlier example, Plotly inferred the image format from the extension of the filename. You can also specify the format explicitly using the format parameter.

import plotly.express as px
data_canada = px.data.gapminder().query("country == 'Canada'")
fig = px.bar(data_canada, x='year', y='pop')
fig.write_image("fig1", format="png")

Write Multiple Images

Kaleido v1 and later

plotly.io provides a write_images function for writing multiple figures to images. Using write_images is faster than calling fig.write_image multiple times.

write_images takes a list of figure objects or dicts representing figures as its first argument, fig. The second argument file is a list of paths to export to. These paths can be specified as strs or pathlib.Path objects.

import plotly.graph_objects as go
import plotly.express as px
import plotly.io as pio


fig1 = go.Figure(
    data=go.Scatter(x=[1, 2, 3], y=[4, 5, 6], mode='lines+markers'),
    layout=go.Layout(title='Line Chart')
)

fig2 = go.Figure(
    data=go.Bar(x=['A', 'B', 'C'], y=[10, 5, 15]),
    layout=go.Layout(title='Bar Chart')
)

fig3 = px.pie(
    values=[30, 20, 10, 40],
    names=['A', 'B', 'C', 'D'],
    title='Pie Chart'
)

pio.write_images(
    fig=[fig1, fig2, fig3],
    file=['export_images/line_chart.png', 'export_images/bar_chart.png', 'export_images/pie_chart.png']
)

Get Image as Bytes

As well as exporting to a file, Plotly figures also support conversion to a bytes object. To convert a figure to a PNG bytes object, call the figure's to_image method with a format

In [1]:
import plotly.express as px
data_canada = px.data.gapminder().query("country == 'Canada'")
fig = px.bar(data_canada, x='year', y='pop')
img_bytes = fig.to_image(format="png")

Here's the bytes object displayed using IPython.display.Image:

In [2]:
from IPython.display import Image
Image(img_bytes)
Out[2]:

Specify Image Dimensions and Scale

In addition to the image format, the to_image and write_image functions provide arguments to specify the image