gpt4 book ai didi

python - 在python中分隔条形图组

转载 作者:行者123 更新时间:2023-12-02 08:50:07 26 4
gpt4 key购买 nike

在下面的代码中,我有两组条形图,每组有 5 个条形图。问题是它们结合在一起并且非常接近。我应该如何将两组条形图分开?

    X = np.arange(2)
barWidth = 0.25
plt.bar(X + 0.00, Unf1_list, color = 'b', width = 0.2,align='center')
plt.bar(X + 0.25, Unf2_list, color = 'g', width = 0.2,align='center')
plt.bar(X + 0.50, Unf3_list, color = 'r', width = 0.2,align='center')
plt.bar(X + 0.75, Unf4_list, color = 'y', width = 0.2,align='center')
plt.bar(X + 1.00, Unf5_list, color = 'gray', width = 0.2,align='center')
plt.yscale('log')
plt.xticks([r + barWidth for r in range(2)], ['z=1', 'z=6'])
plt.show()

最佳答案

我建议您减小条宽,以便各组更加分开

barWidth = 0.15
barSep = 0.01

for i, lst in enumerate([lst1, lst2, lst3, lst4, lst5]):
plt.bar(X + i*(barWidth+barSep), lst, width=barWidth, color=f'C{i}')

plt.yscale('log')
plt.xticks([r + barWidth for r in range(2)], ['z=1', 'z=6'])
plt.show()

输出:

enter image description here

关于python - 在python中分隔条形图组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59105916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com