英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论