python - 在 matplotlib 错误栏中,如何通过不同颜色的颜色传递不同的点?
问题描述
我有
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 参数无效:('lime'、'magenta'、'darkorange'、'cyan'、'cornflowerblue'、'cornflowerblue'、'lime'、'magenta'、'darkorange'、'cyan')
我可以通过遍历所有点并单独绘制它们来解决这个问题:
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
没有这些参数。
解决方案
推荐阅读
- c - How to get lines from two char arrays to check the equality between each of their lines
- c++ - 当 b 大于 15 时,pow(a,b) 返回比实际值小 1?
- php - Drupal 7 dompdf foreach 循环中没有数据
- java - JSON response Not Working, don't know the issue
- c# - CD 中的两个 azure 功能管道部署到一个应用程序服务不工作
- html2canvas - HTML2CANVAS 累积画布
- python - 如何将每个数据帧行值存储在字符串中并执行 URL
- python - 为什么在这种情况下事件总是 pygame.MOUSEBUTTONDOWN ?
- c# - IndexOutOfRange when player reaches maxLevel
- java - My Java Scanner wont stop running. I was trying make a method that alphabetically sorts a string but the scanner wont stop scanning