代码之家  ›  专栏  ›  技术社区  ›  patapouf_ai

在matplotlib错误栏中,如何用不同的颜色传递不同的点?

  •  0
  • patapouf_ai  · 技术社区  · 5 年前

    我有

    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]) 
    

    这给了我类似于: enter image description here

    这正是我想要的。

    但是,有没有一种方法可以在不循环所有点的情况下做到这一点呢?? 关于stackoverflow使用的所有其他答案 cmap colormap 但是 errorbar 没有这些论点。

    0 回复  |  直到 5 年前