fig = plt.figure()
#use a figure size of (20, 8),bar width of 0.8, 设置图片大小,柱宽
#use color #5cb85c for the Very interested bars, 设置柱子颜色
#color #5bc0de for the Somewhat interested bars,
#color #d9534f for the Not interested bars,
c=topicp.plot(kind='bar', y=['Very interested','Somewhat interested','Not interested'],figsize=(20, 8),width=0.8,
color=['#5cb85c','#5bc0de','#d9534f'],fontsize=14)
#use font size 14 for the bar labels, percentages, and legend, 图例颜色
plt.legend(fontsize=14)
#use font size 16 for the title, and, 标题字号
plt.title("Percentage of Respondents' Interest in Data Science Areas",fontsize=16)
plt.yticks([]) # y轴空轴
#display the percentages above the bars as shown above 数据标签列表
x=np.arange(len(topicp.index))
yv=np.array(list(topicp['Very interested']))
ys=np.array(list(topicp['Somewhat interested']))
yn=np.array(list(topicp['Not interested']))
for a,b in zip(x,yv): ##控制标签位置
plt.text(a-0.27,b+0.1,'%.2f'%b,ha = 'center',va = 'bottom',fontsize=14)
for a,b in zip(x,ys):
plt.text(a,b+0.1,'%.2f'%b,ha = 'center',va = 'bottom',fontsize=14)
for a,b in zip(x,yn):
plt.text(a+0.27,b+0.1,'%.2f'%b,ha = 'center',va = 'bottom',fontsize=14)
#remove the left, top, and right borders. 去掉图片边框
c.spines['top'].set_visible(False)
c.spines['right'].set_visible(False)
#c.spines['bottom'].set_visible(False) 保留横坐标边框
c.spines['left'].set_visible(False)
plt.show
https://blog.csdn.net/WallisY/article/details/98482700