重叠的Matplot条形图?

问题描述 投票:0回答:1

我正在用python学习matplot,我想制作带有并排条形图的条形图。由于某些原因,我的情节目前重叠。

Graph

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个不同的图并排出现而不是重叠?

谢谢!

python matplotlib
1个回答
0
投票

@@ ImportanceofBeingErnest通过此链接提供了帮助:https://matplotlib.org/gallery/lines_bars_and_markers/barchart.html

必须修改索引参数以防止重叠。

© www.soinside.com 2019 - 2024. All rights reserved.