直方图的限制取决于输入数据的百分位数。

huangapple go评论70阅读模式
英文:

Histogram limits dependant on percentiles of input data

问题

我希望在我的模拟数据中根据输入百分位数设定最小和最大限制。我有一个可以工作并生成合适图形的函数,但我希望限制异常值。以下是详细的函数。我了解如何使用numpy从数据中计算百分位数,但不知道如何限制各个直方图的轴。

英文:

I wish to put a minimum and maximum limit within my simulated data dependent on input percentiles. I have a function which works and produces an adequate graph but I wish to limit the outliers. The function is detailed below. I understand how to calculate the percentiles from the data using numpy but have no idea how restrict the axis on the individual histograms.

def plotResults(spotData, loadData,\
                    loadTitle = 'Load Simulation Histogram', loadXLabel = 'Simulated Total GWh', loadYLabel = 'freqency'\
                        ,spotTitle = 'Spot Simulation Histogram', spotXLabel = 'Simulated Mean ($/MWh)', spotYLabel = 'freqency'\
                         ,minPerctile = 1, maxPercentile = 99):
  

        fig, axs = plt.subplots(1,2,figsize=(12,6))
        axs[0].hist(loadData/2000, bins = 50)
        axs[0].set_title(loadTitle)
        axs[0].xaxis.set_label_text(loadXLabel)
        axs[0].yaxis.set_label_text(loadYLabel)
        
        axs[1].hist(spotData, bins = 50)
        axs[1].set_title(spotTitle)
        axs[1].xaxis.set_label_text(spotXLabel)
        axs[1].yaxis.set_label_text(spotYLabel)

        plt.show()

答案1

得分: 1

尝试将你的百分位数传递给直方图函数的range参数。

tst_data = np.random.uniform(0., 1., 1000)

low_perc = np.percentile(tst_data, 10)
high_perc = np.percentile(tst_data, 90)

plt.hist(tst_data, bins=10, range=(low_perc, high_perc))
plt.show()
英文:

Try passing your percentiles to the range argument of the histogram function

tst_data = np.random.uniform(0., 1., 1000)

low_perc = np.percentile(tst_data, 10)
high_perc = np.percentile(tst_data, 90)

plt.hist(tst_data, bins=10, range=(low_perc, high_perc))
plt.show()

直方图的限制取决于输入数据的百分位数。

huangapple
  • 本文由 发表于 2023年7月18日 10:50:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76709240.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定