Show Sidebar Hide Sidebar

Matplotlib Static Image Export

How to export plotly matplotlib graphs as static images in Python. Plotly supports png, svg, jpg, and pdf image export.

You can save static images using the save_as method. This is similar to save_fig method available in matplotlib:


# Import modules
import plotly.plotly as py
import plotly.tools as tls
import matplotlib.pyplot as plt

# Create a plot
x = [1, 2]
y = [2, 4]
plt.plot(x, y)

# Get Matplotlib Figure
mpl_fig = plt.gcf() 

# Convert to plotly figure
plotly_fig = tls.mpl_to_plotly(mpl_fig) 

# Save image
py.image.save_as(plotly_fig, 'your_image_filename.png') 

In Addition, you can specify the size of the matplotlib/plotly figure to be saved by using following method:

import plotly.plotly as py
py.image.save_as(plotly_fig, 'your_image_filename.png', height=desired_height, width=desired_width) 

You can also display inline static images in IPython:


import plotly.plotly as py
py.image.ishow(plotly_fig)

You can view the static version of any Plotly graph by appending .png, .pdf, .eps, or .svg to the end of the URL.


For example, view the static image of https://plot.ly/~chris/1638 at https://plot.ly/~chris/1638.png.


Combine this with the requests package and download the latest version of your Plotly graph:


import requests

image_bytes = requests.get('https://plot.ly/~chris/1638.png').content



Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.