首页 > 解决方案 > 如何为误差线分配颜色?[Matplotlib]

问题描述

我是 Matplotlib 的新手,找不到将颜色分配给误差线的方法……在我的数据(附加)中,平均值是“数字”,SD(“错误”)在“sd”列中。我按“应变”(4 个类别;mc、mut1 等)对数据进行分组。颜色是“应变”(线),但错误颜色不匹配。

我希望它们与线条颜色相同(来自颜色矢量“c”)。谢谢!

该文件是https://anonfiles.com/d8A7m4F5o0/mutdp_csv

muts = pd.read_csv('mutdp.csv')
#SUBSET
# Select rows (i.e. 1 to 28)
gr=muts[1:28]

fig, ax = plt.subplots(figsize=(12,9.9))

c=['b','y','r','g']

#Data GR ---------------------------------------------------------------------------------------------
grstrain=gr.groupby(['time','strain']).mean()['numbers'].unstack()
grstrain.plot.line(ax=ax, style=['-o','-o','-o','-o'],color=c, ls = '--', linewidth=2.7)

# Error
ax.errorbar(gr.time, gr.numbers, yerr=gr.sd, ls='')

#(SCALE)
plt.yscale('log')
plt.ylim(0.04, 3)

# Label
ax.set_xlabel('Time (hours)' )
ax.set_ylabel('Growth (OD)')
ax2.set_ylabel('ylabel2')

#SAVE FIG!

plt.show() 

标签: pythonmatplotlibcolorserrorbar

解决方案


推荐阅读