【问题标题】:Color each errorbar with different color用不同的颜色为每个误差条着色
【发布时间】:2013-05-22 12:31:29
【问题描述】:

我正在尝试绘制errorbar 图表,其中每个误差条可能是红色或绿色,具体取决于用于计算条形的统计数据是否显着。
我尝试使用颜色数组作为c 参数的输入,但没有奏效。

有人知道怎么做吗?

这是我目前的代码:

yerrs = np.array([quantiles[:,2],quantiles[:,3]])
print yerrs.shape
colors = ['r', 'b'] * (yerrs.shape[1]/2)
fig, axes = plt.subplots(nrows=2, sharex=True, sharey=True)
axes[0].errorbar(quantiles[:,0],quantiles[:,1], yerr=yerrs, c=colors)
axes[0].axhline(0, color='black')
axes[0].axvline(0, color='black')
axes[0].set_title('Fitted dist')

然后我得到错误:

ValueError: to_rgba: Invalid rgba arg "['r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b']"
could not convert string to float: r

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    将您的数据数组分成两组,并使用“ecolor”指定错误栏颜色。

    axes[0].errorbar(x1, y1, yerr=yerr1, ecolor="r")
    axes[0].errorbar(x2, y2, yerr=yerr2, ecolor="b")
    

    如何将数据分成第 1 部分和第 2 部分对您来说应该是微不足道的,但如果您不确定,请告诉我。

    【讨论】:

    • 谢谢!这几乎正​​是我想要做的,除了连接点的线对于每个图都是分开的。如果他们能在同一条线上就好了。
    • @user1094206 不确定您的确切意思 --- 您希望它们位于同一行,然后使用相同的 x 和 y 而不是 x1/2 和 y1/2 绘制它们... .
    猜你喜欢
    • 2022-01-24
    • 2020-06-04
    • 1970-01-01
    • 1970-01-01
    • 2020-03-06
    • 2018-10-12
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    相关资源
    最近更新 更多