Matplotlib hist()-如何强制使箱子宽度相等?

Matplotlib hist()-如何强制使箱子宽度相等?,matplotlib,pandas,Matplotlib,Pandas,假设我有以下数组:[1,1,1,2,2,40,60,70,75,80,85,87,95]我想根据下面的箱子创建一个柱状图-x听起来像你想要一个条形图;您可以使用bar: import numpy as np import matplotlib.pyplot as plt arr=np.array([1,1,1,2,2,40,60,70,75,80,85,87,95]) h=np.histogram(arr,bins=(0,2,80,100)) plt.bar(range(3),h[0],widt

假设我有以下数组:
[1,1,1,2,2,40,60,70,75,80,85,87,95]
我想根据下面的箱子创建一个柱状图-
x听起来像你想要一个条形图;您可以使用
bar

import numpy as np
import matplotlib.pyplot as plt
arr=np.array([1,1,1,2,2,40,60,70,75,80,85,87,95])
h=np.histogram(arr,bins=(0,2,80,100))
plt.bar(range(3),h[0],width=1)
xlab=['x<=2', '3<=x<=80]', 'x>=81']
plt.xticks(arange(0.5,3.5,1),xlab)
将numpy导入为np
将matplotlib.pyplot作为plt导入
arr=np.数组([1,1,1,2,2,40,60,70,75,80,85,87,95])
h=np.直方图(arr,bins=(0,2,80100))
plt.bar(范围(3),h[0],宽度=1)
xlab=['xsee