import numpy as np import matplotlib.pyplot as plt plt.rcParams["font.sans-serif"] = ["SimHei"] plt.rcParams["axes.unicode_minus"] = False month_x = np.arange(1, 13, 1) data_A= np.array([47,64,31,23,29,42,25,33,65,63,63,61]) data_B= np.array([28,66,183,207,83,176,165,174,377,288,168,203]) fig, ax = plt.subplots() bar_A = ax.bar(month_x, data_A, color='b', tick_label=['5日','6日','7日','8日','9日','10日','11日','12日','13日','14日','15日','16日'],width=bar_width) bar_B = ax.bar(month_x+bar_width, data_B, color='r',width=bar_width) ax.set_ylabel('在售数量(个)') ax_right = ax.twinx() ax_right.set_ylabel('求购数量(个)') ax.set_title('在售数量与求购数量对比图') plt.legend([bar_A, bar_B], ['在售数量', '求购数量'], shadow=True, fancybox=True) plt.xticks(month_x+bar_width/2) plt.ylim([0,400]) plt.grid(axis='y', linestyle='--') plt.show()修改为误差棒图
时间: 2023-11-21 15:06:18 浏览: 61
Matplotlib二维箭头图制作.docx
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
month_x = np.arange(1, 13, 1)
data_A= np.array([47,64,31,23,29,42,25,33,65,63,63,61])
data_B= np.array([28,66,183,207,83,176,165,174,377,288,168,203])
fig, ax = plt.subplots()
bar_width = 0.35
bar_A = ax.bar(month_x, data_A, color='b', tick_label=['5日','6日','7日','8日','9日','10日','11日','12日','13日','14日','15日','16日'], width=bar_width, yerr=np.random.rand(len(month_x))*5)
bar_B = ax.bar(month_x+bar_width, data_B, color='r',width=bar_width, yerr=np.random.rand(len(month_x))*5)
ax.set_ylabel('数量(个)')
ax_right = ax.twinx()
ax_right.set_ylabel('数量(个)')
ax.set_title('在售数量与求购数量对比图')
plt.legend([bar_A, bar_B], ['在售数量', '求购数量'], shadow=True, fancybox=True)
plt.xticks(month_x+bar_width/2)
plt.ylim([0,400])
plt.grid(axis='y', linestyle='--')
plt.show()
阅读全文