lets_plot.ggsave#

lets_plot.ggsave(plot: PlotSpec | SupPlotsSpec | GGBunch, filename: str, *, path: str | None = None, iframe: bool = True, scale: float | None = None, w: float | None = None, h: float | None = None, unit: str | None = None, dpi: int | None = None) str#

Export plot or bunch to a file. Supported formats: PNG, SVG, PDF, HTML.

The exported file is created in directory ${user.dir}/lets-plot-images if not specified otherwise (see the path parameter).

Parameters:
plotPlotSpec or GGBunch

Plot specification to export.

filenamestr

The name of file. It must end with a file extension corresponding to one of the supported formats: SVG, HTML (or HTM), PNG (requires CairoSVG library), PDF.

pathstr

Path to a directory to save image files in. By default it is ${user.dir}/lets-plot-images.

iframebool, default=True

Whether to wrap HTML page into a iFrame. Only applicable when exporting to HTML. Some browsers may not display some UTF-8 characters correctly when setting iframe=True

scalefloat, default=2.0

Scaling factor for raster output. Only applicable when exporting to PNG or PDF.

wfloat, default=None

Width of the output image in units. Only applicable when exporting to PNG or PDF.

hfloat, default=None

Height of the output image in units. Only applicable when exporting to PNG or PDF.

unit{‘in’, ‘cm’, ‘mm’}, default=None

Unit of the output image. One of: ‘in’, ‘cm’, ‘mm’. Only applicable when exporting to PNG or PDF.

dpiint, default=None

Resolution in dots per inch. Only applicable when exporting to PNG or PDF.

Returns:
str

Absolute pathname of created file.

Examples

1from lets_plot import *
2LetsPlot.setup_html()
3plot = ggplot() + geom_point(x=0, y=0)
4ggsave(plot, 'plot.html', path='.', iframe=False)

1from lets_plot import *
2LetsPlot.setup_html()
3plot = ggplot() + geom_point(x=0, y=0) + ggsize(800, 400)
4ggsave(plot, 'plot.png', w=8, h=4, unit='in', dpi=300)