python绘制柱状图形+柱状图增加数字标注
复制代码
1
2
3
4
5
6
7
8
9
10
11
12data = pd.Series([4, 5, 6], index=['A','B','C']) fig = plt.figure(figsize=(7, 5), dpi=90) # 声明画布1 ax = fig.add_subplot(1,1,1) # 声明绘图区 x, y = data.index, data.values rects = plt.bar(x, y, color='dodgerblue', width=0.35, label='label1') plt.grid(linestyle="-.", axis='y', alpha=0.4) plt.legend() plt.tight_layout()
注:line= plt.bar(label=‘label’) # 这里的label参数 表示当前 x,y 图形的图例名称
方法一:
复制代码
1
2
3
4
5for rect in rects: #rects 是三根柱子的集合 height = rect.get_height() plt.text(rect.get_x() + rect.get_width() / 2, height, str(height), size=15, ha='center', va='bottom')
方法二:
复制代码
1
2
3
4for a,b in zip(x,y): plt.text(a, b-0.3,'%.3f'%b, ha = 'center',va = 'bottom',fontsize=15) plt.show()
plt.text(相关参数)
plt.text(x,y,str) #x,y :位置坐标; str :标注内容
最后
以上就是高大啤酒最近收集整理的关于python plt绘制柱状图形+柱状图增加数字标注python绘制柱状图形+柱状图增加数字标注方法一:方法二:的全部内容,更多相关python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复