我有
fig, axs = plt.subplots(shape[1], shape[0], figsize=(9, 3 * shape[1]), sharey=True)
for idx, ax in enumerate(axs.reshape(-1)):
categorical_labels = ...
values = ...
errors = ...
colours = ...
ax.errorbar(categorical_labels, values, yerr=errors, fmt='.', ecolor=colours, mfc=colours, mec=colours)
这行不通,因为
ecolor
,
mfc
并且,
mec
不要接受颜色列表(每个点一种颜色),一旦看到颜色列表,它就会认为它是RGBA颜色。因此,它给出了错误:
ValueError:无效的RGBA参数:(“time”、“洋红色”、“暗橙色”、“青色”、“矢车菊蓝”、“cornflowersblue”、“石灰”、“洋红”、“深橙色”和“青色”)
我可以通过遍历所有点并单独绘制来解决这个问题:
for i, v in enumerate(values):
ax.errorbar([categorical_labels[i]], [values[i]], yerr=[errors[i]], fmt='.', ecolor=colours[i], mfc=colours[i], mec=colours[i])
这给了我类似于:
这正是我想要的。
但是,有没有一种方法可以在不循环所有点的情况下做到这一点呢??
关于stackoverflow使用的所有其他答案
cmap
或
colormap
但是
errorbar
没有这些论点。