python - 重叠的matplot条形图?
问题描述
我正在用python学习matplot,我想用并排的条形图制作一个条形图。由于某种原因,我的情节目前正在重叠。
import numpy as np
import matplotlib.pyplot as plt
n_groups = 7
means_frank = (82, 75, 86, 63, 90, 73 ,88)
means_alex = (91, 92, 80, 73, 83, 91, 71)
means_joe = (72, 42, 50, 33, 63, 34, 54)
fig = plt.figure()
ax = fig.add_subplot(111)
index = np.arange(n_groups)
bar_width = 0.27
opacity = 0.8
rects1 = ax.bar(index,means_frank,bar_width,color='b', label="Frank")
rects2 = ax.bar(index,means_alex,bar_width,color='g', label="Alex")
rects3 = ax.bar(index,means_joe,bar_width,color='r', label="Joe")
plt.ylabel('Scores')
plt.title('Test Scores')
plt.xticks([0, 5, 6], ["Assignments -->", "<-- Midterm", "Final"])
plt.legend()
plt.tight_layout()
plt.show()
如何使这 3 个不同的图并排而不是重叠出现?
谢谢!
解决方案
@ImportanceofBeingErnest 帮助了这个链接: https ://matplotlib.org/gallery/lines_bars_and_markers/barchart.html
必须修改 index 参数以防止重叠。
推荐阅读
- android - Android总是在后台停止音频流
- angular - 如何将 primeNg 下拉选择值设置为对象的 id 而不是整个对象
- mysql - 货量有限、人流量大的订舱数据库MySQL查询设计
- c++ - 推导将被称为重载构造函数的类型
- forms - 使用参数提交表单以执行操作,Asp.Net.Core Mvc
- javascript - 为什么 cookieParser 不返回值?
- java - 转义正则表达式变量
- python - 加载 TensorFlow 嵌入模型
- mysql - 如何在 mysql 中保存和检索图像?
- python - 如何使用 BeautifulSoup 在包含多个表的页面上选择一个表