Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将颜色指定给错误栏大写?[Matplotlib]_Python_Matplotlib_Errorbar - Fatal编程技术网

Python 如何将颜色指定给错误栏大写?[Matplotlib]

Python 如何将颜色指定给错误栏大写?[Matplotlib],python,matplotlib,errorbar,Python,Matplotlib,Errorbar,我是Matplotlib的新手,希望为错误条帽指定颜色…在我的数据(附件)中,平均值为“数字”,SD(“错误”)位于“SD”列中。我按“应变”(4类;mc、mut1等)对数据进行分组。颜色是“线”。下面的代码可以工作,但当我使用“翻覆”添加大写时,它会抛出一个错误 我希望瓶盖的颜色与线条的颜色相同(从颜色向量“c”),有什么办法吗?谢谢 文件是 由于ax.errorbar只接受一种固定颜色,因此可以在循环中为每种颜色调用一次。以下代码创建一些随机数据,以显示如何编写循环: 从matplotlib

我是Matplotlib的新手,希望为错误条帽指定颜色…在我的数据(附件)中,平均值为“数字”,SD(“错误”)位于“SD”列中。我按“应变”(4类;mc、mut1等)对数据进行分组。颜色是“线”。下面的代码可以工作,但当我使用“翻覆”添加大写时,它会抛出一个错误

我希望瓶盖的颜色与线条的颜色相同(从颜色向量“c”),有什么办法吗?谢谢

文件是


由于
ax.errorbar
只接受一种固定颜色,因此可以在循环中为每种颜色调用一次。以下代码创建一些随机数据,以显示如何编写循环:

从matplotlib导入pyplot作为plt
导入matplotlib
将numpy作为np导入
作为pd进口熊猫
gr=pd.DataFrame({'time':np.tile(范围(0,14,2,4)),
“应变”:np.重复(['mc','mut1','mut2','mut3'],7),
“数字”:0.1+np.random.uniform(-0.01,0.06,28).cumsum(),
'sd':np.随机.均匀(0.01,0.05,28)})
图,ax=plt.子批次(图尺寸=(12,9.9))
颜色=['b','y','r','g']
grstrain=gr.groupby(['time','strain']).mean()['numbers'].unstack()
grstrain.plot.line(ax=ax,style=['-o','-o','-o','-o','-o'],color=colors,ls='--',线宽=2.7)
对于应变,拉链中的颜色(np.独特(gr.应变),颜色):
grs=gr[gr.应变==应变]
最大误差条(grs.time,grs.numbers,yerr=grs.sd,ls='',color=color,翻船=3,capthick=3)
plt.yscale('log')
plt.ylim(0.04,3)
plt.show()

嘿,太棒了,谢谢!我会将其应用于我的数据,并让您知道它是如何运行的!:)嗨,约翰,很抱歉我回复晚了,刚刚用新数据检查了一下,效果很好!谢谢
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 (-----HERE is where "capsize" causes the error----)
ax.errorbar(gr.time, gr.numbers, yerr=gr.sd, ls='', color=[i for i in c for _i in range(7)], capsize=3, capthick=3)

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


#SAVE FIG!

plt.show()