Python:直方图-创建uequal bins/axis
注意,此问题与:[有关。 我有一个像这样的数据Python:直方图-创建uequal bins/axis,python,matplotlib,histogram,clip,Python,Matplotlib,Histogram,Clip,注意,此问题与:[有关。 我有一个像这样的数据 时间压力 1/1/2017 0:00 5.8253 ... ... 3/1/2017 0:10 4.2785 4/1/2017 0:20 5.20041 5/1/2017 0:30 4.40774 6/1/2017 0:40 4.03228 7/1/2017 0:50 5.011924 2017年12月1日1:00 3.9309888您
时间压力
1/1/2017 0:00 5.8253
... ...
3/1/2017 0:10 4.2785
4/1/2017 0:20 5.20041
5/1/2017 0:30 4.40774
6/1/2017 0:40 4.03228
7/1/2017 0:50 5.011924
2017年12月1日1:00 3.9309888
您可以使用numpy.histogram()
生成直方图,然后使用Axes.bar()
绘制它。然后可以使用轴调整刻度。设置_ticklebels()
。以下是一个示例:
import numpy as np
from matplotlib import pyplot as plt
#some fake data:
data = np.random.normal(70,20,[100])
#the histogram
dist, edges = np.histogram(data,bins=[0,40,60,65,70,75,80])
#the plot
fig,ax = plt.subplots()
ax.bar(
np.arange(dist.shape[0]), dist, width=1, align = 'edge',
color = [1,0,0,0.5], edgecolor=[1,0,0,1], lw = 2,
)
ax.set_xticks(np.arange(edges.shape[0]))
ax.set_xticklabels(edges)
plt.show()
整个事情看起来是这样的:
希望这有帮助。可能重复@EvgenyPogrebnyak:我希望x轴上的值[0,40,60,65,70,75,80]与图像类似。您是否尝试将代码组合在一起以实现此目的?为什么不在此处发布?