import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
x = np.arange(3)
y1 = np.array([2.14, 1.56, 1.75])
y2 = np.array([1.56, 1.41, 1.82])
y3 = np.array([4.86, 4.11, 4.54])
y4 = np.array([3.35, 2.22, 4.85])
error1 = [0.23, 0.04, 0.11]
error2 = [0.30, 0.16, 0.18]
error3 = [0.39, 0.31, 0.24]
error4 = [0.28, 0.29, 0.29]
bar_width = 0.5
plt.bar(x, y1, bar_width)
plt.bar(x + bar_width, y2, bar_width, tick_label=["春季", "夏季", "秋季"])
plt.bar(x + 2*bar_width, y3, bar_width)
plt.bar(x + 3*bar_width, y4, bar_width)
plt.errorbar(x, y1, yerr=error1, capsize=3, elinewidth=2, linestyle='none', color='black')
plt.errorbar(x + bar_width, y2, yerr=error2, capsize=3, elinewidth=2, linestyle='none')
plt.errorbar(x + 2*bar_width, y3, yerr=error3, capsize=3, elinewidth=2, linestyle='none')
plt.errorbar(x + 3*bar_width, y4, yerr=error4, capsize=3, elinewidth=2, linestyle='none')
plt.show()
绘制误差棒
于 2023-10-07 23:01:13 首次发布