# -*- coding: utf-8 -*-
"""
Created on Wed Feb 8 11:44:13 2023
@author: wangchao
"""
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['SimHei']
def drawHistogram():
#matplotlib.rc("font", family='MicroSoft YaHei')
#plt.rcParams['font.sans-serif'] = ['SimHei']
# plt.rcParams['axes.unicode_minus'] = False
#list1 = np.array([89.3, 90.2, 91.8, 91.8, 91.6]) # 柱状图第一组数据
#list2 = np.array([81.6, 83.7, 84.2, 84.4, 84.1]) # 柱状图第二组数据
list1 = np.array([89.7, 90.9, 91.8, 92.2, 91.4]) # 柱状图第一组数据
list2 = np.array([82.2, 84.3, 84.2, 85.3, 84.7]) # 柱状图第二组数据
length = len(list1)
x = np.arange(length) # 横坐标范围
listDate = ["0", "0.1", "0.2", "0.3", "0.4"]
plt.figure()
total_width, n = 0.8, 2 # 柱状图总宽度,有几组数据
width = total_width / n # 单个柱状图的宽度
x1 = x - width / 2 # 第一组数据柱状图横坐标起始位置
x2 = x1 + width # 第二组数据柱状图横坐标起始位置
#plt.title("一周每天吃悠哈软糖颗数柱状图") # 柱状图标题
# plt.xlabel("星期") # 横坐标label 此处可以不添加
plt.ylabel("Accuracy") # 纵坐标label
plt.xlabel("Sn") # 纵坐标label
plt.bar(x1, list1, width=width, label="Ran1")
plt.bar(x2, list2, width=width, label="mAP")
plt.xticks(x, listDate) # 用星期几替换横坐标x的值
for a, b in zip(x1, list1):
plt.text(a, b + 0.1, '%.01f' % b, ha='center', va='bottom', fontsize=7)
for a, b in zip(x2, list2):
plt.text(a, b + 0.1, '%.01f' % b, ha='center', va='bottom', fontsize=7)
plt.legend(loc='center left') # 给出图例
plt.savefig('12345.pdf')
plt.show()
if __name__ == '__main__':
drawHistogram()