Python:多个QQ图 [英] Python: Multiple QQ-Plot
问题描述
我是新来的,通常来自 R.我想用多行创建一个QQ图.
I am new and usually coming from R. I want to create a QQ-Plot wit multiple lines.
我有一个 beta 分布式数据集我想为 beta 分布尝试不同的参数,并在 one QQ-Plot 中比较它们以进行更好的比较.如果我尝试下面的代码,每个图都有相同的颜色,我得到了 3 条 QQ 线.有没有可能将这三个QQ图合二为一?
我希望你能解决我的问题
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)
亲切的推荐
推荐答案
好吧,stats.probplot
让我有点困惑.该文档明确指出:
Okay, so stats.probplot
has left me a little confused. The documentation clearly states that:
probplot
生成概率图,不应与Q-Q 或 P-P 图.
probplot
generates a probability plot, which should not be confused with a Q-Q or a P-P plot.
然而,我能找到的所有来源都表明概率图是指 Q-Q 图或 P-P 图.去图.
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.
无论如何,就我而言,您生成的是一个 Q-Q 图.
Anyway, as far as I'm concerned, what you've generated is a Q-Q plot.
在我看来,stats.probplot
的选项 fit=False
被忽略,并且总是向数据添加回归线.
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.
无论如何,为了得到你想要的,我们可以显式地创建一个 matplotlib 轴实例,并使用 get_lines
方法去除不需要的回归线并改变标记颜色.
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:
这篇关于Python:多个QQ图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!