# Python | Quantile-Quantile Plot using SciPy

Q-Q plot is a plot between Quantile of x (one Variable) and Quantile of y (another Variable).

Quantile:  Quantile word comes from the word ‘Quantity’. Quantile is simply defined as the sample which is equally distributed with a periodic interval of time.

There are three types of Q-Q plots:

• Exactly same: When all the quantile points lie on the same linear line. This line is exactly at the 45-degree angle from either of the axis. Practically all the quantile points are not exactly on the same linear line but they are plotted around that line only. This kind of plot is Normal Distribution.
• Towards X-axis: The quantile points will plot on a curve which is having bulge towards the x-axis. Same with this too, points do not plot on a fixed curve line, the plot around that line, spread across the side of the line towards x- axis. It shows that y values have a tendency to be lower than the x values.
• Towards Y-axis: The quantile points will plot on a curve line having a bulge towards the y-axis. Here also points do not plot on a fixed curve line. Rather, the plot around that line spreading across the side of the line towards y-axis showing the x values to be lower than y-values.

Example:

Normal Distribution: If we take both the sets from the same sample. Then it will roughly plot a straight line with the help of quantile points.

scipy.stats.probplot() plots data against a probability distribution where the default value for dist is the norm which generates a Normal Distribution.

Below is the given Python code example for Quantile-Quantile Plot using SciPy module:

```#import the required libraries
# import NumPy, pylab, and scipy.
import numpy as np
import pylab
import scipy.stats as stats

# Draw random sample using normal distribution
measure = np.random.normal(loc = 20, scale = 5, size=50)   #set center i.e. mean = 20
#generate probability plot and set distribution to normal
stats.probplot(measure, dist="norm", plot=pylab)
pylab.show()```

In this example, data samples random values using the normal distribution, and as a result, it will plot a linear Q-Q plot.