How to plot prob plots

Probability plots convert the plotting positions into quantiles or probability distribution. Probability plots only check if a data set follows a given distribution. The default being standard-normal (Z) distribution.

To use, import the library:

from scipy import stats

The default implementation of prob plot is:

scipy.stats.probplot(x = None sparms= (), dist= norm, fit:bool = True, plot= None, rvalue:bool = False)

Parameters

  • x: array-like - The sample from which probplot creates the plot.

  • sparams: tuple - Distribution-specific shape parameters.

  • dist: str or stats.distribution instance - Distribution or distribution function name.

  • fit: bool - Fits a least-squares regression (best-fit) line to the sample data.

  • plot: object - Plots the quantiles and least-squares fit if given. A plot is an object that has to have methods “plot” and “text”. The matplotlib.pyplot module, a Matplotlib Axes object, or a custom object with the same methods can be used.

Return

  • (osm, osr): tuple - It returns a tuple of theoretical quantities and ordered responses.

  • (slope, intercept, r): tuple - Tuple containing the least-square fit, intercept, and the square root of the coefficient of determination. If fit = False and plot = None, nothing is returned.

Code

The following code shows how prob plots can be added in Python. You can change the parameters to see how the output varies.

main.py
dataset.csv
from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
#generate random values
np.random.seed(223)
#draw a distribution
x = stats.t.rvs(25, size = 100)
#plot the graph
res = stats.probplot(x, plot=plt)
#show the graph
plt.show()

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved