Python-保存条形图中的颜色,类似于获取线条图的颜色()

Python-保存条形图中的颜色,类似于获取线条图的颜色(),python,matplotlib,Python,Matplotlib,是否有办法将条形图的颜色保存在变量中,以用于设置轴的记号和标签颜色?我知道这是可能的使用get_color()线图,但它不适用于条形图 style_format='seaborn' mpl.style.use(style_format) fig, ax_1 = plt.subplots() ax_2 = ax_1.twinx() ax_2.grid(None) plot_1, = ax_1.errorbar(df['date'].tolist(), ptt['avg'].tolist(),

是否有办法将条形图的颜色保存在变量中,以用于设置轴的记号和标签颜色?我知道这是可能的使用get_color()线图,但它不适用于条形图

style_format='seaborn'
mpl.style.use(style_format)

fig, ax_1 = plt.subplots()
ax_2 = ax_1.twinx()
ax_2.grid(None)
plot_1, = ax_1.errorbar(df['date'].tolist(), ptt['avg'].tolist(), 
                         yerr=df['std'].tolist(), fmt='-o')
bar_1 = ax_2.bar(df['date'].tolist(), df['count'].tolist(), alpha=0.25)

plot_1_color = plot_1.get_color()
#this is where the code breaks. have tried get_facecolor() as well
bar_1_color = bar_1.get_color()

ax_1.yaxis.label.set_color(plot_1_color)
ax_2.yaxis.label.set_color(bar_1_color)
我在matplotlib文档或其他任何地方都没有找到这样做的方法。非常感谢您的帮助


感谢

返回调用
ax.bar
(a
BarContainer
)的相关文档可在此处找到:。此外,您不需要对series对象调用
.tolist()
。您可以简单地按原样传递它们。您可能有多个条,而这些条不一定具有相同的颜色。因此,您需要选择一个条形图并使用其颜色,
bar\u 1[0]。获取\u facecolor()
。谢谢。删除.tolist()调用时会出现错误,这就是我最初添加该调用的原因。感谢您的回复。