Export to PNG with ggsave()

To export plot to a PNG file you should install the CairoSVG library to your Python environment.

In [1]:
import pandas as pd

from lets_plot import *
In [2]:
LetsPlot.setup_html()
In [3]:
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv")
df.head()
Out[3]:
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa

Plot

In [4]:
p = ggplot(df) + geom_point(aes('petal_length', 'petal_width', color='species'), size=5) + ggsize(600, 400)
p
Out[4]:

Export to PNG file

To save plot as a PNG file use a filename that have "png" extension.

In [5]:
image_path = ggsave(p, "plot.png")
In [6]:
from IPython.display import Image

Image(image_path, width=600, height=400)
Out[6]: