为每个错误栏涂上不同的颜色 [英] Color each errorbar with different color

查看:42
本文介绍了为每个错误栏涂上不同的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to plot an errorbar graph where each error bar may be either, say, red or green depending on whether the statistics used to compute the bar are significant.
I tried using an array of colors as an input to the c parameter, but that didn't work.

有人知道怎么做吗?

这是我到目前为止的代码:

Here is the code that I have so far:

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

推荐答案

将数据数组分为两组,并使用"ecolor"指定错误栏颜色.

separate your data array into two groups and use "ecolor" to specify errorbar color.

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

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

How to separate data into portions 1 and 2 should be trivial to you, but let me know if you are uncertain.

这篇关于为每个错误栏涂上不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆