嘿,我在 matplotlib 中有这个条形图,我想在红线所在的位置(不是红条)之间添加一些空白,并调整 x-ticks,使它们位于每组条形之下。对于我现在在 jupyter 笔记本中的内容,我有以下最小示例(尽管使用的是假数据集):import numpy as npimport matplotlib.pyplot as pltset1 = [16.4, 9.5, 9.53, 9.57, 9.0]set2 = [0.8, 1.90, 1.90, 1.90, 1.90]set3 = [16.19, 2.86, 2.86, 2.86, 13.55]set4 = [12721.93, 3.81, 3.81, 3.81, 3.81]x = np.arange(5)plt.bar(x+0.00, set1, color = 'b', hatch="/", width=0.25)plt.bar(x+0.25, set2, color = 'r', hatch="\\", width=0.25)plt.bar(x+0.50, set3, color = 'g', hatch="x", width=0.25)plt.bar(x+0.75, set4, color = 'y', hatch="*", width=0.25)plt.xticks(np.arange(5, step=1), ['Set1', 'Set2', 'Set3', 'Set4', 'Set5'])plt.yscale('log',basey=10)plt.tight_layout()对于如何使用 matplotlib 实际执行此操作的想法,我完全空白,因此不胜感激。
1 回答

翻阅古今
TA贡献1780条经验 获得超5个赞
x您可以通过更改第一个参数 ( ) 和 的参数width来调整条的放置位置和条的宽度plt.bar。像这样的东西应该工作:
plt.bar(x-0.3, set1, color = 'b', hatch="/", width=0.2)
plt.bar(x-0.1, set2, color = 'r', hatch="\\", width=0.2)
plt.bar(x+0.1, set3, color = 'g', hatch="x", width=0.2)
plt.bar(x+0.3, set4, color = 'y', hatch="*", width=0.2)
添加回答
举报
0/150
提交
取消