将料仓与XTICK对齐plt.his公司

2024-06-12 05:47:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在根据气候模型制作降水率平均值的柱状图,柱状图函数起作用了,但是x轴让我有点烦。我想在每个箱子之间有一个刻度,比如2.55。然而,一些滴答声消失了,主要是在左侧。我有什么办法可以把它们对齐吗?在

x = np.arange(0.006,0.0345,0.0015)
print (x)

#Make historical (1979-2015) histogram
plt.figure(figsize=(11,7))
plt.hist(histmeans, 19, color='#808080')

#labels & axes
#plt.locator_params(nbins=19, axis='x')
plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
plt.title('Precip. Flux Anomaly (1979-2015 means, CanESM2 Hist)',fontsize=20)
plt.xlabel('Precip. Flux Mean (mm/day)',fontsize=15)
plt.ylabel('Number of Members',fontsize=15)
plt.xticks(x)
plt.xlim(0.006,0.0345)

print (np.min(histmeans))
print (np.max(histmeans))

输出:

^{pr2}$

enter image description here


Tags: 函数模型npplt平均值气候printaxis
1条回答
网友
1楼 · 发布于 2024-06-12 05:47:13

plt.hist接受选项bins,它可以是整数(如脚本中所示),也可以是bin边的列表。因此,您可以使用您定义为x的bin边范围作为bins选项,来设置您感兴趣的精确bin边。在

x = np.arange(0.006,0.0345,0.0015)
plt.hist(histmeans, bins = x, color='#808080')

以下是全文:

^{pr2}$

输出如下:

[ 0.006   0.0075  0.009   0.0105  0.012   0.0135  0.015   0.0165  0.018
  0.0195  0.021   0.0225  0.024   0.0255  0.027   0.0285  0.03    0.0315
  0.033   0.0345]
[ 0.006   0.0075  0.009   0.0105  0.012   0.0135  0.015   0.0165  0.018
  0.0195  0.021   0.0225  0.024   0.0255  0.027   0.0285  0.03    0.0315
  0.033   0.0345]
0.00661096260281
0.0341882193394

enter image description here

相关问题 更多 >