如何优化此代码?条形图Matplotlib Python

时间:2019-04-21 02:41:23

标签: python pandas matplotlib data-visualization

我觉得我写了太多代码,无法将标签放在每个小节上方。如何优化此代码?

数据集为ds_survey

ds_survey.plot(kind ='bar', 
          figsize=(10, 8),
          width = 0.35, 
         )

xlocs, xlabs = plt.xticks()
y = ds_survey['Interested']
for i, v in enumerate(y):
    plt.text(xlocs[i] - 0.35, v + 0.4, str(v))

y = ds_survey['Little interested']
for i, v in enumerate(y):
    plt.text(xlocs[i] - 0.1, v + 0.4, str(v))

y = ds_survey['Dont Want']
for i, v in enumerate(y):
    plt.text(xlocs[i]+0.2, v + 0.4, str(v))

plt.show()

0 个答案:

没有答案