save_plot

save_plot(
    plot,
    path=None,
    width=PLOT_WIDTH,
    height=PLOT_HEIGHT,
    dpi=PLOT_DPI,
    bg='transparent',
    **kwargs,
)

Quick-save a plot to PNG, SVG or PDF.

A thin, pipe-friendly wrapper around plotnine’s ggplot.save() that picks the format from the file extension and uses presentation-friendly defaults (transparent background, generous size). Returns the plot, so it drops into a pipeline without breaking it (p.pipe(save_plot, "p.png")).

Parameters

Name Type Description Default
plot plotnine.ggplot A plotnine chart. required
path str Output path; the extension sets the format (.png, .svg, .pdf, .jpg, .jpeg, .tiff). None (default) writes plot.png. A bare file name lands in ezrsurvey-outputs/ (created on demand); a path naming a directory (“./x.png”, “charts/x.png”, anything absolute) is used exactly as given. See the output_dir option. None
width float Size in inches. Default 8 x 4.5. PLOT_WIDTH
height float Size in inches. Default 8 x 4.5. PLOT_WIDTH
dpi int Raster resolution for PNG/JPG/TIFF. Default 300. PLOT_DPI
bg str Background fill. Default “transparent” (matches the ezrsurvey themes); use “white” for a solid background. 'transparent'
**kwargs Passed to ggplot.save(). {}

Returns

Name Type Description
plotnine.ggplot The plot.

See Also

save_data, save_output

Examples

>>> import tempfile, os
>>> p = plot_bars(calc_percentage(podracing_survey, "demo_gender"))
>>> tmp = os.path.join(tempfile.mkdtemp(), "chart.png")
>>> save_plot(p, tmp)
>>> os.path.exists(tmp)