lets_plot.bistro.qq.qq_plot#
- lets_plot.bistro.qq.qq_plot(data=None, sample=None, *, x=None, y=None, distribution=None, dparams=None, quantiles=None, group=None, show_legend=None, color=None, fill=None, alpha=None, size=None, shape=None, line_color=None, line_size=None, linetype=None) PlotSpec #
Produce a Q-Q plot (quantile-quantile plot).
Supply the sample parameter to compare distribution of observations with a theoretical distribution (‘normal’ or as otherwise specified by the distribution parameter).
Alternatively, supply x and y parameters to compare the distribution of x with the distribution of y.
- Parameters:
- datadict or Pandas or Polars DataFrame
The data to be displayed.
- samplestr
Name of variable specifying a vector of observations used for computing of “sample quantiles”. Use this parameter to produce a “sample vs. theoretical” Q-Q plot.
- x, ystr
Names of variables specifying two vectors of observations used for computing of x and y “sample quantiles”. Use these two parameters to produce a “sample X vs. sample Y” Q-Q plot.
- distribution{‘norm’, ‘uniform’, ‘t’, ‘gamma’, ‘exp’, ‘chi2’}, default=’norm’
Distribution function to use. Could be specified if sample is.
- dparamslist
Additional parameters (of float type) passed on to distribution function. Could be specified if sample is. If distribution is ‘norm’ then dparams is a pair [mean, std] (=[0.0, 1.0] by default). If distribution is ‘uniform’ then dparams is a pair [a, b] (=[0.0, 1.0] by default). If distribution is ‘t’ then dparams is an integer number [d] (=[1] by default). If distribution is ‘gamma’ then dparams is a pair [alpha, beta] (=[1.0, 1.0] by default). If distribution is ‘exp’ then dparams is a float number [lambda] (=[1.0] by default). If distribution is ‘chi2’ then dparams is an integer number [k] (=[1] by default).
- quantileslist, default=[0.25, 0.75]
Pair of quantiles to use when fitting the Q-Q line.
- groupstr
Grouping parameter. If it is specified and color-parameters isn’t then different groups will has different colors.
- show_legendbool, default=True
False - do not show legend.
- colorstr
Color of a points. For more info see https://lets-plot.org/python/pages/aesthetics.html#color-and-fill.
- fillstr
Color to paint shape’s inner points. Is applied only to the points of shapes having inner points. For more info see https://lets-plot.org/python/pages/aesthetics.html#color-and-fill.
- alphafloat, default=0.5
Transparency level of points. Accept values between 0 and 1.
- sizefloat, default=3.0
Size of the points.
- shapeint
Shape of the points, an integer from 0 to 25. For more info see https://lets-plot.org/python/pages/aesthetics.html#point-shapes.
- line_colorstr, default=’#FF0000’
Color of the fitting line. For more info see https://lets-plot.org/python/pages/aesthetics.html#color-and-fill.
- line_sizefloat, default=0.75
Width of the fitting line.
- linetypeint or str
Type of the fitting line. Codes and names: 0 = ‘blank’, 1 = ‘solid’, 2 = ‘dashed’, 3 = ‘dotted’, 4 = ‘dotdash’, 5 = ‘longdash’, 6 = ‘twodash’. For more info see https://lets-plot.org/python/pages/aesthetics.html#line-types.
- Returns:
- PlotSpec
Plot object specification.
Notes
The Q-Q plot is used for comparing two probability distributions (sample and theoretical or two sample) by plotting their quantiles against each other.
If the two distributions being compared are similar, the points in the Q-Q plot will approximately lie on the straight line.
Examples
1import numpy as np 2from lets_plot.bistro.qq import qq_plot 3from lets_plot import * 4LetsPlot.setup_html() 5n = 100 6np.random.seed(42) 7x = np.random.normal(0, 1, n) 8qq_plot(data={'x': x}, sample='x')
1import numpy as np 2from lets_plot.bistro.qq import qq_plot 3from lets_plot import * 4LetsPlot.setup_html() 5n = 100 6np.random.seed(42) 7x = np.random.exponential(1, n) 8qq_plot({'x': x}, 'x', \ 9 distribution='exp', quantiles=[0, .9], \ 10 color='black', line_size=.25)
1import numpy as np 2from lets_plot.bistro.qq import qq_plot 3from lets_plot import * 4LetsPlot.setup_html() 5n = 100 6np.random.seed(42) 7data = { 8 'x': np.random.normal(0, 1, n), 9 'y': np.random.normal(1, 2, n), 10 'g': np.random.choice(['a', 'b'], n), 11} 12qq_plot(data, x='x', y='y', group='g', \ 13 shape=21, alpha=.2, size=5, linetype=5)
1import numpy as np 2from lets_plot.bistro.qq import qq_plot 3from lets_plot import * 4LetsPlot.setup_html() 5n = 150 6np.random.seed(42) 7data = { 8 'x': np.random.normal(0, 5, n), 9 'g': np.random.choice(['a', 'b', 'c'], n), 10} 11qq_plot(data, 'x', dparams=[0, 5], group='g', \ 12 line_color='black', line_size=.5) + \ 13 scale_color_brewer(type='qual', palette='Set1') + \ 14 facet_grid(x='g') + \ 15 coord_fixed() + \ 16 xlab("Norm distribution quantiles") + \ 17 ggtitle("Interaction of the qq_plot() with other layers") + \ 18 theme_classic()