简体   繁体   English

如何根据第一个 dataframe 列的值更改条形图的 xticks?

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

I have a dataframe that looks like this:我有一个看起来像这样的 dataframe:

data = {'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]
  }
df = pd.DataFrame(data)

I would like to create a stacked bar plot with the numbers of the column 'QA score' as xticks.我想创建一个堆叠条 plot ,其中“QA 分数”列的数字为 xticks。

Right now I have got this plot:现在我有这个 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') x 轴从 0 到 14 应设置为 0 到 7,步长为 0.5(如在“QA 分数”列中)

I tried resetting the index with df.set_index(['QA Score']) and tried plt.xticks() but it all does not work.我尝试使用df.set_index(['QA Score'])重置索引并尝试plt.xticks()但这一切都不起作用。

Anyone has an idea how to do this?任何人都知道如何做到这一点? Thanks in advance!提前致谢!

What about:关于什么:

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

output: output:

堆积条形图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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