我正在按照这个教程进行学习:
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())
当我尝试执行pX.get_color()时,出现以下错误:
AttributeError: 'AxesSubplot'对象没有属性'get_color'
我的问题是:我应该使用哪种方法来恢复子图的颜色?
我知道我可以手动设置颜色以匹配,因为这只需要很少的指令,但我想知道是否还有其他方法。
谢谢
ax.bar
进行工作,并想要获取最新的颜色。以下是我解决这个问题的方法,以防其他人遇到相同的问题:bars = ax.bar(x, height)
和c = bars.patches[-1].get_facecolor()
- Johann