How To Make The Width Of Histogram Columns All The Same
I'm having a bit of trouble manipulating a histogram. I have a df with two columns and I'm plotting them as a stacked histogram. I'm putting them into specific bins (see code below
Solution 1:
Make all bins the same size, then clip your data to the right end of the last bin.
df=pd.DataFrame(np.random.randint(0,4000,size=(100,2)),columns=['A','B'])df['A'].loc[85:89]=np.random.randint(5000,10000,size=5)bins= [0,400,800,1200,1600,2000,2400,2800,3200,3600,4000,4400]
df.clip(upper=4400).plot.hist(stacked=True,bins=bins,normed=True)
Take into account that, as pointed in the comments, this is not really a histogram. You might want to customize the labels to reflect the fact that the last bin is actually larger than it looks.
Post a Comment for "How To Make The Width Of Histogram Columns All The Same"