python - 如何为误差线分配颜色?[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()
解决方案
推荐阅读
- javascript - 如何在 React 中将一个组件的功能重用到另一个组件
- php - 如何查询类别数组以获取 Laravel 中的帖子?
- macos - 如何替换 csv 文件中除一列之外的所有匹配项。awk csv bash mac
- javascript - 添加任何值时如何自动加载网页
- java - 为什么 CFX 拦截器不能在 spring-boot 中工作?
- r - 有没有更简单的方法来记住我们可以在 R 编程中使用管道函数的顺序?
- git - 如何在本地和远程重新定位?
- python - 单词转换
- android - android:网络安全配置仅在调试版本
- hadoop - 在 hdfs 文件上运行 awk 脚本并将结果文件保存在 hdfs 中