如何获得matplotlib中最后一个数字的颜色? [英] How can I get the color of the last figure in matplotlib?

查看:161
本文介绍了如何获得matplotlib中最后一个数字的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用线性拟合绘制一些数据集。我想要线性拟合具有与绘制数据相同的颜色(误差条)。

I'm plotting some data sets with linear fits. I want the linear fit to have the same color as the plotted data (error bars). How can I get that color?

推荐答案

您可以尝试这样:

x = np.arange(10)
y = np.arange(10)
err = np.ones(10)
ebar = plt.errorbar(x,y, yerr=err)
color = ebar[0].get_color()

ebar 是艺术家的容器,因此您可以修改最后一行中的索引,以匹配您想要获取颜色的艺术家。

ebar is a container of artist, so you might modify the index in the last line to match the artist you want to get color from.

您还可以轻松设置错误栏的颜色,因此您可以准确地知道它们是什么颜色,而无需检查它们:

You can also easily set the color of the errorbar, so you know exactly what color they are without checking it:

ebar = plt.errorbar(x,y, yerr=err, ecolor='y')

这篇关于如何获得matplotlib中最后一个数字的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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