Calculate quantiles for a probability plot, and optionally show the plot.
Generates a probability plot of sample data against the quantiles of a
specified theoretical distribution (the normal distribution by default).
probplot optionally calculates a best-fit line for the data and plots the
results using Matplotlib or a given plot function.
Parameters:
xarray_like
Sample/response data from which probplot creates the plot.
sparamstuple, optional
Distribution-specific shape parameters (shape parameters plus location
and scale).
diststr or stats.distributions instance, optional
Distribution or distribution function name. The default is ‘norm’ for a
normal probability plot. Objects that look enough like a
stats.distributions instance (i.e. they have a ppf method) are also
accepted.
fitbool, optional
Fit a least-squares regression (best-fit) line to the sample data if
True (default).
plotobject, optional
If given, plots the quantiles.
If given and fit is True, also plots the least squares fit.
plot is an object that has to have methods "plot" and "text".
The matplotlib.pyplot module or a Matplotlib Axes object can be used,
or a custom object with the same methods.
Default is None, which means that no plot is created.
rvaluebool, optional
If plot is provided and fit is True, setting rvalue to True
includes the coefficient of determination on the plot.
Default is False.
Returns:
(osm, osr)tuple of ndarrays
Tuple of theoretical quantiles (osm, or order statistic medians) and
ordered responses (osr). osr is simply sorted input x.
For details on how osm is calculated see the Notes section.
(slope, intercept, r)tuple of floats, optional
Tuple containing the result of the least-squares fit, if that is
performed by probplot. r is the square root of the coefficient of
determination. If fit=False and plot=None, this tuple is not
returned.
Notes
Even if plot is given, the figure is not shown or saved by probplot;
plt.show() or plt.savefig('figname.png') should be used after
calling probplot.
probplot generates a probability plot, which should not be confused with
a Q-Q or a P-P plot. Statsmodels has more extensive functionality of this
type, see statsmodels.api.ProbPlot.
The formula used for the theoretical quantiles (horizontal axis of the
probability plot) is Filliben’s estimate:
where i indicates the i-th ordered value and n is the total number
of values.
Array API Standard Support
probplot has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.