Skip to content Skip to sidebar Skip to footer

Python Display Same Bin Width For Different Bin Sizes

I have this code bins = [0,1,10,20,30,40,50,75,100] plt.figure(figsize=(15,15)) plt.hist(df.v1, bins = bins) My problem is that the bin widths as they appear in the figure are pro

Solution 1:

I'm not sure how you'll make sense of the result, but you can use numpy.histogram to calculate the height of your bars, then plot those directly against an arbitrary x-scale.

x = np.random.normal(loc=50, scale=200, size=(2000,))
bins = [0,1,10,20,30,40,50,75,100]
fig = plt.figure()
ax = fig.add_subplot(211)
ax.hist(x, bins=bins, edgecolor='k')
ax = fig.add_subplot(212)
h,e = np.histogram(x, bins=bins)
ax.bar(range(len(bins)-1),h, width=1, edgecolor='k')

enter image description here

Post a Comment for "Python Display Same Bin Width For Different Bin Sizes"