我试图绘制一个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')
Run Code Online (Sandbox Code Playgroud)
然后我得到错误:
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
Run Code Online (Sandbox Code Playgroud)
将数据数组分成两组,并使用"ecolor"指定错误栏颜色.
axes[0].errorbar(x1, y1, yerr=yerr1, ecolor="r")
axes[0].errorbar(x2, y2, yerr=yerr2, ecolor="b")
Run Code Online (Sandbox Code Playgroud)
如何将数据分成第1部分和第2部分对您来说应该是微不足道的,但如果您不确定,请告诉我.
| 归档时间: |
|
| 查看次数: |
3566 次 |
| 最近记录: |