Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change xticks of bar chart according to values of first dataframe column?

I have a dataframe that looks like this:

df = {'QA Score': [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7],
   'Scopus': [0,0,0,0,0,1,0,0,1,3,2,3,6,4,2],
   'ResearchGate': [0,0,0,0,0,0,1,1,2,3,2,1,0,2,1],
   'Taylor&Francis': [0,0,0,0,0,0,0,0,0,1,0,0,2,0,0],
   'ACM': [0,0,0,0,1,1,3,3,0,4,2,5,0,0,0]
  }

I would like to create a stacked bar plot with the numbers of the column ‘QA score’ as xticks.

Right now I have got this plot:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

stacked bar plot

The x axis from 0 to 14 should be set to 0 to 7 with steps of 0.5 (as in column ‘QA score’)

I tried resetting the index with df.set_index(['QA Score']) and tried plt.xticks() but it all does not work.

Anyone has an idea how to do this? Thanks in advance!

>Solution :

What about:

df.set_index('QA Score').plot.bar(stacked=True)

output:

stacked bar plot

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading