numpy 直方图限值取决于输入数据的百分位数

mum43rcc  于 2023-08-05  发布在  其他
关注(0)|答案(1)|浏览(84)

我希望把我的模拟数据的最小和最大限度取决于输入百分位数。我有一个函数,它可以工作并产生足够的图形,但我希望限制异常值。该功能详述如下。我知道如何使用numpy从数据中计算百分位数,但不知道如何限制各个直方图上的轴。

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()

字符串

tjrkku2a

tjrkku2a1#

尝试将百分比传递给直方图函数的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()

字符串


的数据

相关问题