Skip to content Skip to sidebar Skip to footer

Python: Multiple Qq-plot

I am new and usually coming from R. I want to create a QQ-Plot wit multiple lines. I have a beta distributed dataset I want to try different parameters for the beta distribution a

Solution 1:

Okay, so stats.probplot has left me a little confused. The documentation clearly states that:

probplot generates a probability plot, which should not be confused with a Q-Q or a P-P plot.

Yet all the sources I can find state that a probability plot refers to either a Q-Q plot or P-P plot. Go figure.

Anyway, as far as I'm concerned, what you've generated is a Q-Q plot.

It also seems to me that the option fit=False of stats.probplot is ignored, and a regression line is always added to the data.

Anyway, to get what you desire, we can explicitly create a matplotlib axes instance, and use the get_lines method to remove the unwanted regression lines and change the marker colours.

import scipy.stats as stats
import numpy as np
import matplotlib.pyplot as plt

plt.style.use('seaborn')

x = numpy.random.beta(2, 3, size=100)

fig, ax = plt.subplots(1, 1, figsize=(6, 4))
stats.probplot(x, dist=stats.beta, sparams=(2,3), plot=plt, fit=False)
stats.probplot(x, dist=stats.beta, sparams=(1,2), plot=plt, fit=False)
stats.probplot(x, dist=stats.beta, sparams=(1,4), plot=plt, fit=False)

# Remove the regression lines
ax.get_lines()[1].remove()
ax.get_lines()[2].remove()
ax.get_lines()[3].remove()

# Change colour of scatter
ax.get_lines()[0].set_markerfacecolor('C0')
ax.get_lines()[1].set_markerfacecolor('C1')
ax.get_lines()[2].set_markerfacecolor('C2')

# Add on y=x line
ax.plot([0, 1], [0, 1], c='C3')

This gave me the following, which I think this time really is what you desired:

enter image description here

Post a Comment for "Python: Multiple Qq-plot"