You can export figure created by ggplot()
or gggrid()
functions
to a vector or raster format using the following methods:
to_svg(path)
to_html(path, iframe)
to_png(path, scale)
to_pdf(path, scale)
To save plot to a file on disc, specify the file' pathname in path
.
To stream plot image to a file-like object, supply such object in the path
parameter instead of a pathname.
import numpy as np
import io
from IPython import display
from lets_plot import *
LetsPlot.setup_html()
data = {'x': np.random.normal(size=100)}
p = ggplot(data, aes(x='x')) + geom_histogram()
path = p.to_svg('lets-plot-images/hist.svg')
display.SVG(path)
stream = io.BytesIO()
p.to_svg(stream)
display.SVG(stream.getvalue())