如何更改 statsmodels qqplot 的绘图属性? (Python)
How to change plot properties of statsmodels qqplot? (Python)
所以我正在使用 statsmodels.graphics.gofplots.qqplot() 绘制一个正常的 Q-Q 图。
模块使用matplotlib.pyplot创建图形实例。它很好地绘制了图表。
但是,我想用 alpha=0.3 绘制标记。
有办法吗?
这是一个代码示例:
import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt
test = np.random.normal(0,1, 1000)
sm.qqplot(test, line='45')
plt.show()
以及输出图:
qqplot
returns a figure
object which can be used to get the lines
which can then be modified using set_alpha
fig = sm.qqplot(test, line='45');
# Grab the lines with blue dots
dots = fig.findobj(lambda x: hasattr(x, 'get_color') and x.get_color() == 'b')
[d.set_alpha(0.3) for d in dots]
很明显,这些点有一点重叠,所以即使它们的 alpha 值很低,但它们在彼此堆叠的地方看起来更不透明。
您可以使用 statsmodels.graphics.gofplots.ProbPlot class which has qqplot method to pass matplotlib pyplot.plot **kwargs。
import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt
test = np.random.normal(0, 1, 1000)
pp = sm.ProbPlot(test, fit=True)
qq = pp.qqplot(marker='.', markerfacecolor='k', markeredgecolor='k', alpha=0.3)
sm.qqline(qq.axes[0], line='45', fmt='k--')
plt.show()
所以我正在使用 statsmodels.graphics.gofplots.qqplot() 绘制一个正常的 Q-Q 图。
模块使用matplotlib.pyplot创建图形实例。它很好地绘制了图表。
但是,我想用 alpha=0.3 绘制标记。
有办法吗?
这是一个代码示例:
import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt
test = np.random.normal(0,1, 1000)
sm.qqplot(test, line='45')
plt.show()
以及输出图:
qqplot
returns a figure
object which can be used to get the lines
which can then be modified using set_alpha
fig = sm.qqplot(test, line='45');
# Grab the lines with blue dots
dots = fig.findobj(lambda x: hasattr(x, 'get_color') and x.get_color() == 'b')
[d.set_alpha(0.3) for d in dots]
很明显,这些点有一点重叠,所以即使它们的 alpha 值很低,但它们在彼此堆叠的地方看起来更不透明。
您可以使用 statsmodels.graphics.gofplots.ProbPlot class which has qqplot method to pass matplotlib pyplot.plot **kwargs。
import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt
test = np.random.normal(0, 1, 1000)
pp = sm.ProbPlot(test, fit=True)
qq = pp.qqplot(marker='.', markerfacecolor='k', markeredgecolor='k', alpha=0.3)
sm.qqline(qq.axes[0], line='45', fmt='k--')
plt.show()