【发布时间】:2020-12-06 06:15:05
【问题描述】:
我正在使用以下代码在 3 个不同的数据集 a、b 和 c 上制作 5 个条形图。如何在每个栏中显示所有颜色。我不希望他们的价值加起来。例如,在第一个栏中,如果Green 的值为1,Yellow 为3 并且Red 为6 我不希望最终值为10 而应该是6 但所有颜色都应该出现直到它们的最终值。我不想使用透明颜色或只使用条形轮廓。
import matplotlib.pyplot as plt
import numpy as np
a = [1, 2, 3, 4, 5]
b = [3, 4, 1, 10, 9]
c = [6, 7, 2, 4, 6]
ind = np.arange(len(a))
fig = plt.figure()
ax = fig.add_subplot(111)
ax.bar(x=ind, height=a, width=0.35, align='center', label='Green',
facecolor='g')
ax.bar(x=ind, height=b, width=0.35, align='center', label='Yellow',
facecolor='y')
ax.bar(x=ind, height=c, width=0.35, align='center', label='Red', facecolor='r')
plt.xticks(ind, a)
plt.xlabel('Coordination Number')
plt.ylabel('Frequency')
plt.legend()
plt.show()
【问题讨论】:
-
这两个答案对您的问题有帮助吗?
标签: python matplotlib data-visualization histogram