简体   繁体   中英

how to draw a histogram in python matplotlib?

我的数据名为range_freq

my data with name called as ranges_freq as below

    buckets     userid  
 0   10           730  
 1   50           435  
 2   100          150  
 3   500          314  
 4   1000         97  
 5   1001         244  

I am able to draw a bar chart by using the below code but i am unable to draw a histogram for the same data.

>y = ranges_freq['userid']
 xlabels = ranges_freq['buckets']
 bar_width = 0.50
 x = np.arange(len(y))
 fig, ax = plt.subplots()
 ax.bar(x, y, width=bar_width)
 ax.set_xticks(x + (bar_width/2.0))
 ax.set_xticklabels(xlabels)
 ax.set_title('User Frequency by range')
 ax.set_xlabel('buckets')
 ax.set_ylabel('no.of.users')
 plt.show()

这是我如何获得条形图的图像

so how can i draw the histogram for the samedata with same parmeters that i have used for the barchart please help me how to draw the histogram in same way?

So to remove the spaces in your bar chart, the only thing you need to do, is to set

bar_width = 1.0

Result: 在此处输入图片说明

But you have to understand that this is a bar chart (just without spaces in between the bars).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM