相当于MATLAB的normplot的Python吗? [英] Python equivalent for MATLAB's normplot?
问题描述
是否存在与MATLAB中的normplot
类似的python等效函数?
也许在matplotlib中?
Is there a python equivalent function similar to normplot
from MATLAB?
Perhaps in matplotlib?
MATLAB语法:
x = normrnd(10,1,25,1);
normplot(x)
赠予:
我尝试使用matplotlib& numpy模块确定数组中值的概率/百分位数,但输出图的y轴比例与MATLAB中的图相比是线性的.
I have tried using matplotlib & numpy module to determine the probability/percentile of the values in array but the output plot y-axis scales are linear as compared to the plot from MATLAB.
import numpy as np
import matplotlib.pyplot as plt
data =[-11.83,-8.53,-2.86,-6.49,-7.53,-9.74,-9.44,-3.58,-6.68,-13.26,-4.52]
plot_percentiles = range(0, 110, 10)
x = np.percentile(data, plot_percentiles)
plt.plot(x, plot_percentiles, 'ro-')
plt.xlabel('Value')
plt.ylabel('Probability')
plt.show()
赠予:
否则,如何像第一幅图那样调整比例?
Else, how could the scales be adjusted as in the first plot?
谢谢.
推荐答案
一个较新的答案,但我遇到了同样的问题,找到了一个值得分享的解决方案.我想.
A late answer, but I just came across the same problem and found a solution, that is worth sharing. I guess.
正如joris指出的那样,probplot函数与normplot等效,但是结果分布采用累积密度函数的形式. Scipy.stats还提供了转换这些值的功能.
As joris pointed out the probplot function is an equivalent to normplot, but the resulting distribution is in form of the cumulative density function. Scipy.stats also offers a function, to convert these values.
cdf->百分位数
stats.'distribution function'.cdf(cdf_value)
百分位数-> cdf
percentile -> cdf
stats.'distribution function'.ppf(percentile_value)
例如:
stats.norm.ppf(percentile)
要获得等效的y轴(如normplot),可以替换cdf-ticks:
To get an equivalent y-axis, like normplot, you can replace the cdf-ticks:
from scipy import stats
import matplotlib.pyplot as plt
nsample=500
#create list of random variables
x=stats.t.rvs(100, size=nsample)
# Calculate quantiles and least-square-fit curve
(quantiles, values), (slope, intercept, r) = stats.probplot(x, dist='norm')
#plot results
plt.plot(values, quantiles,'ob')
plt.plot(quantiles * slope + intercept, quantiles, 'r')
#define ticks
ticks_perc=[1, 5, 10, 20, 50, 80, 90, 95, 99]
#transfrom them from precentile to cumulative density
ticks_quan=[stats.norm.ppf(i/100.) for i in ticks_perc]
#assign new ticks
plt.yticks(ticks_quan,ticks_perc)
#show plot
plt.grid()
plt.show()
结果:
这篇关于相当于MATLAB的normplot的Python吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!