相关疑难解决方法(0)

如何获取matplotlib中最后一个数字的颜色?

我正在绘制一些线性拟合的数据集.我希望线性拟合具有与绘制数据相同的颜色(误差条).我怎样才能得到那种颜色?

python colors matplotlib

12
推荐指数
1
解决办法
4897
查看次数

子图的 matplotlib get_color

我正在关注这里的教程:https : //matplotlib.org/gallery/ticks_and_spines/multiple_yaxis_with_spines.html
但是,使用的示例是针对单个图的,我目前正在处理子图。我的版本如下:

    p1 = tr[names['equity']].plot(ax=ax3, linewidth = 0.75)
    axb = ax3.twinx()
    axb.spines["right"].set_position(("axes", 0.5))
    p2 = tr[names[local_rating]].plot(ax=axb, c= 'r', linewidth = 0.75)
    axb.grid(False)
    axb.margins(x=0)
    axc = ax3.twinx()    
    p3 = tr[names['vol']].plot(ax=axc, c = 'g', linewidth = 0.75)
    axc.grid(False)
    axc.margins(x=0)
    ax3.yaxis.label.set_color(p1.get_color())
    axb.yaxis.label.set_color(p2.get_color())
    axc.yaxis.label.set_color(p3.get_color())
Run Code Online (Sandbox Code Playgroud)

当我尝试执行 pX.get_color() 时,我得到:

AttributeError: 'AxesSubplot' 对象没有属性 'get_color'

我的问题是:我应该使用什么方法来恢复子图的颜色?

我知道我可以手动设置颜色来匹配,因为它是少量的指令,但我只是想知道是否有另一种方法。

谢谢

python matplotlib

6
推荐指数
1
解决办法
2591
查看次数

标签 统计

matplotlib ×2

python ×2

colors ×1