更新时间:2023-11-22 09:47:04
好吧,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: