Skip to content

PlotSpec

PlotSpec(
    data: PlotData | None,
    mapping: FeatureSpec | None,
    scales: Iterable[FeatureSpec],
    layers: Iterable[FeatureSpec],
    metainfo_list: Iterable[FeatureSpec] = (),
    **kwargs: object,
)

Bases: ggrust.plot.core.FeatureSpec

A plot: data, mapping, layers, scales and features. Build it with ggplot().

as_dict

as_dict() -> dict[str, Any]

Return the plot as a lets_plot-compatible dictionary.

Returns:

  • dict –

    Keys as lets_plot's PlotSpec.as_dict(): data (the frame object itself), mapping, kind, scales, layers, metainfo_list, ...

duplicate classmethod

duplicate(other: PlotSpec) -> PlotSpec

Return a shallow copy of other.

Parameters:

  • other (PlotSpec) –

    The spec to copy.

get_plot_shared_data

get_plot_shared_data() -> PlotData | None

Return the data shared by all layers.

has_layers

has_layers() -> bool

Return whether the plot has at least one layer.

show

show() -> None

Draw the plot: inline in Jupyter/IPython, else in the default browser.

Outside IPython the interactive HTML page is written to a temporary file and opened in the browser (lets_plot prints the spec dict there).

Examples:

>>> from ggrust import ggplot, geom_point
>>> (ggplot() + geom_point(x=0, y=0)).show()

to_html

to_html(
    path: Target | None = None, iframe: bool | None = None
) -> str | None

Render to a standalone HTML page (inline SVG + the interactive runtime).

Parameters:

  • path (str or file - like, default: None ) –

    Where to write. When None, the HTML text is returned.

  • iframe (bool, default: None ) –

    Return an <iframe srcdoc> sized to the plot instead of a page, as lets_plot. Default False.

Returns:

  • str or None –

    The HTML text, the absolute path written to, or None for a file-like target.

to_pdf

to_pdf(
    path: Target,
    scale: Number | None = None,
    w: Number | None = None,
    h: Number | None = None,
    unit: str | None = None,
    dpi: Number | None = None,
) -> str | None

Render to a one-page raster PDF (the PNG at its resolution), as lets_plot.

Parameters:

  • path (str or file - like) –

    Where to write.

  • scale (optional, default: None ) –

    As to_png; the page size is the pixel size divided by the resolution.

  • w (optional, default: None ) –

    As to_png; the page size is the pixel size divided by the resolution.

  • h (optional, default: None ) –

    As to_png; the page size is the pixel size divided by the resolution.

  • unit (optional, default: None ) –

    As to_png; the page size is the pixel size divided by the resolution.

  • dpi (optional, default: None ) –

    As to_png; the page size is the pixel size divided by the resolution.

Returns:

  • str or None –

    The absolute path written to, or None for a file-like target.

Raises:

  • ValueError –

    As to_png.

to_png

to_png(
    path: Target,
    scale: Number | None = None,
    w: Number | None = None,
    h: Number | None = None,
    unit: str | None = None,
    dpi: Number | None = None,
) -> str | None

Render to PNG, sized as lets_plot.

Parameters:

  • path (str or file - like) –

    Where to write.

  • scale (float, default: None ) –

    Pixel scale: 2.0 by default, 1.0 once w and h, dpi or unit is given.

  • w (float, default: None ) –

    Output size (give both). In px: that many pixels (times scale). In in / cm / mm (inches when unit is None): laid out at 96 px per inch, rendered at dpi (times scale).

  • h (float, default: None ) –

    Output size (give both). In px: that many pixels (times scale). In in / cm / mm (inches when unit is None): laid out at 96 px per inch, rendered at dpi (times scale).

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

    Unit of w and h.

  • dpi (float, default: None ) –

    Resolution: 300 by default for physical sizes. Without w and h it scales the plot's own size by dpi / 96. Written to the PNG (pHYs).

Returns:

  • str or None –

    The absolute path written to, or None for a file-like target.

Raises:

  • ValueError –

    On an unknown unit, only one of w / h, a unitless size of 20 or more (looks like pixels), or a non-positive dpi / scale.

to_svg

to_svg(
    path: Target | None = None,
    w: Number | None = None,
    h: Number | None = None,
    unit: str | None = None,
) -> str | None

Render to SVG.

Parameters:

  • path (str or file - like, default: None ) –

    Where to write. When None, the SVG text is returned.

  • w (float, default: None ) –

    Override the plot size (give both).

  • h (float, default: None ) –

    Override the plot size (give both).

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

    Unit of w and h; inches when None. Physical units become the SVG's width / height (laid out at 96 px per inch).

Returns:

  • str or None –

    The SVG text, the absolute path written to, or None for a file-like target.