Skip to content

ggsave

ggsave(
    plot: PlotSpec | SupPlotsSpec,
    filename: str | PathLike[str],
    *,
    path: str | PathLike[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

Save a plot to path/filename; the extension picks the format.

Parameters:

  • plot (PlotSpec or SupPlotsSpec) –

    The figure.

  • filename (str) –

    File name with extension: .svg, .png, .pdf, .html or .htm.

  • path (str, default: None ) –

    Directory; ./lets-plot-images when None (as lets_plot).

  • iframe (bool, default: True ) –

    HTML only: write an <iframe srcdoc> sized to the plot (as lets_plot).

  • scale (float, default: None ) –

    PNG / PDF pixel scale (see PlotSpec.to_png).

  • w (float, default: None ) –

    Output size (svg, png, pdf); give both.

  • h (float, default: None ) –

    Output size (svg, png, pdf); give both.

  • unit (('in', cm, mm, px), default: "in" ) –

    Unit of w and h; inches when None.

  • dpi (int, default: None ) –

    PNG / PDF resolution; 300 by default for physical sizes.

Returns:

  • str –

    Absolute path of the written file.