当前位置:网站首页>matplotlib画柱状图并添加数值到图中

matplotlib画柱状图并添加数值到图中

2022-07-06 15:59:00 L-M-Y

matplotlib画图细节可参考前文:
https://blog.csdn.net/qq_52109814/article/details/121901438?spm=1001.2014.3001.5501

from matplotlib import pyplot as plt
import numpy as np

#编辑图例
def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        #设置图例字体、位置、数值等等
        plt.text(rect.get_x(), 1.01*height, '%s' %
                 float(height), size=11, family="Times new roman")

y = ['A', 'B', 'C', 'D', 'E', 'F']
x = [6.624, 7.394, 14.972, 17.545, 21.239, 16.736]
rect = plt.bar(y, x, width=0.5)
autolabel(rect)
plt.title("Overall Value S")
plt.xlabel("Area")
plt.ylabel("Variance")
plt.legend()

plt.show()

运行示例:
请添加图片描述

原网站

版权声明
本文为[L-M-Y]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_52109814/article/details/125573783