Skip to content

qq_plot

qq_plot(
    data: PlotData | None = None,
    sample: str | None = None,
    *,
    x: str | None = None,
    y: str | None = None,
    distribution: Distribution | None = None,
    dparams: Sequence[float] | None = None,
    quantiles: Sequence[float] | None = None,
    group: str | None = None,
    show_legend: bool | None = None,
    marginal: str | None = None,
    color: str | None = None,
    fill: str | None = None,
    alpha: float | None = None,
    size: float | None = None,
    shape: int | str | None = None,
    line_color: str | None = None,
    line_size: float | None = None,
    linetype: int | str | Sequence[Any] | None = None,
) -> PlotSpec

Draw a Q-Q plot: sample quantiles against theoretical (or other sample) quantiles.

As lets_plot's qq_plot. Give sample to compare a column with a theoretical distribution, or x and y to compare two columns. Points show the quantile pairs, a line goes through the pair of quantiles, and the margins show the distributions of the quantiles on each axis.

Parameters:

  • data (DataFrame or dict, default: None ) –

    The data.

  • sample (str, default: None ) –

    Column of observations to compare with distribution.

  • x (str, default: None ) –

    Columns of observations to compare with each other (both, without sample).

  • y (str, default: None ) –

    Columns of observations to compare with each other (both, without sample).

  • distribution ((norm, uniform, t, gamma, exp, chi2), default: "norm" ) –

    Theoretical distribution, with sample.

  • dparams (list of float, default: None ) –

    Parameters of distribution (see geom_qq), with sample.

  • quantiles (list of float, default: [0.25, 0.75] ) –

    The two quantiles the line goes through.

  • group (str, default: None ) –

    Column grouping the observations: quantiles, lines and margins per group, colored by group unless color / line_color is given.

  • show_legend (bool, default: True ) –

    False hides the legend.

  • marginal (str, default: "dens:tr" ) –

    The margins as "geom:sides[:size]" items separated by commas: geom one of "dens"/"density", "hist"/"histogram", "box"/"boxplot", sides any of "t", "b", "l", "r", size a share of the plot (see ggmarginal); "none" draws no margins.

  • color (str, default: None ) –

    Color of the points and of the margins' outlines.

  • fill (str, default: None ) –

    Fill of the points (shapes 21 to 25) and of the margins.

  • alpha (float, default: 0.5 ) –

    Transparency of the points and of the margins' fill, in 0..1.

  • size (float, default: 3.0 ) –

    Size of the points.

  • shape (int or str, default: None ) –

    Shape of the points, 0 to 25.

  • line_color (str, default: "#FF0000" ) –

    Color of the line (one line per group, in the group color, when group is given and line_color is not).

  • line_size (float, default: 0.75 ) –

    Width of the line.

  • linetype (int or str or list, default: None ) –

    Type of the line: a code 0 to 6, a name such as "dashed", a hex string or a dash list.

Returns:

  • PlotSpec –

    The plot; add more layers, scales, facets and themes with +.

Raises:

  • SpecError –

    If neither sample nor both x and y are given, if both kinds are given, or if a marginal item is not accepted.

  • ColumnNotFoundError –

    If a named column is not in data (raised while computing the margins).

Examples:

>>> import numpy as np
>>> from ggrust import *
>>> from ggrust.bistro.qq import qq_plot
>>> rng = np.random.default_rng(42)
>>> data = {"waiting": rng.exponential(10, 150), "group": rng.choice(["a", "b"], 150)}
>>> plot = qq_plot(data, "waiting", distribution="exp", group="group")

Two samples against each other, by x and y:

>>> pair = {"monday": rng.normal(20, 4, 150), "friday": rng.normal(24, 6, 150)}
>>> plot = qq_plot(pair, x="monday", y="friday", marginal="hist:tr")

Two samples against each other, by x and y