matplotlib - Plotting bar graph with the range in the x- axis -Python -


suppose have data such following, want plot bar graph show each value of range separate bar in x-axis , count in yaxis.

                 range  count 0                  0-2  172 1                02-05   82 2                05-10  117 3                10-15  164 4                15-20  141 5         20 , above  380 

i tried following,

plt.bar(a['range'], a['count'], color='blue') 

but getting following error,

valueerror: invalid literal float(): 0-2 

i tried converting string. still result same. can me in plotting here?

thanks

if @ documentation plt.bar, need specify first argument left edges of bars want, not labels. , specify xtick labels, need use plt.xticks function. this:

plt.bar(range(len(a['count'])), a['count'], color='blue') plt.xticks(range(len(a['count'])), a['range']) 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -