2

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 and compare them in one QQ-Plot for better comparison. If I try the following code, every plot has the same color and I got 3 QQ-lines. Is there a possibility to bring all this three QQ-plots into one?
I hope you get my problem

import scipy.stats as stats
import numpy
x=numpy.random.beta(2, 3, size=100)
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)

Kind regrads

2
  • I'm not sure I understand your question. Importing matplotlib.pyplot as plt and running the above I get a single QQ-plot with multiple lines. Isn't that what you want? Here is the plot I generated Commented Mar 13, 2019 at 13:33
  • yeah but I need online one red line (QQ-line) and the three blue lines in different colors to distinguish them. sorry if that wasn't clear Commented Mar 14, 2019 at 8:16

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much so far, can I somehow erase the red lines and just fit one QQ-line?
But I thought the QQ-Line is always a 45 degree line
Ok thank you, so if I want the above as a QQ plot I have to use an other function?
I think I've got to the bottom of all my confusion. Please see my above edit.
Thank you very much that is exactly what I want

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.