简体   繁体   English

如何在 seaborn 条形图中使用调色板,同时为一个特定的条着色?

[英]How to use color palette in seaborn barplot while coloring one specific bar?

fig1, ax1 = plt.subplots()
sns.barplot(x,y,data,ax=ax1,**palette='vlag'**,ci=None)

plt.show()

The above code can color the bars obtained in specific pallete, now If I want one bar to look different, I can use the below code:上面的代码可以对特定调色板中获得的条进行着色,现在如果我想让一个条看起来不同,我可以使用下面的代码:

fig1, ax1 = plt.subplots()
sns.barplot(x,y,data,ax=ax1,ci=None)

for bar in ax1.patches:
    if bar.get_height()==some value:
        bar.set_color('green')
    else:
        bar.set_color('orange')

plt.show()

Now, what I want to do is, use one specific bar being colored for some value while all other bars in some palette.现在,我想做的是,使用一个特定的条来为某个值着色,而在某个调色板中使用所有其他条。

I looked at custom color palette section, but it wasn't helpful.我查看了自定义调色板部分,但没有帮助。

fig1, ax1 = plt.subplots()
sns.barplot(x,y,data,ax=ax1,**palette='vlag'**,ci=None)

plt.show()

The above code can color the bars obtained in specific pallete, now If I want one bar to look different, I can use the below code:上面的代码可以对特定调色板中获得的条进行着色,现在如果我想让一个条看起来不同,我可以使用下面的代码:

fig1, ax1 = plt.subplots()
sns.barplot(x,y,data,ax=ax1,ci=None)

for bar in ax1.patches:
    if bar.get_height()==some value:
        bar.set_color('green')
    else:
        bar.set_color('orange')

plt.show()

Now, what I want to do is, use one specific bar being colored for some value while all other bars in some palette.现在,我想做的是,使用一个特定的条来为某个值着色,而在某个调色板中使用所有其他条。

I looked at custom color palette section, but it wasn't helpful.我查看了自定义调色板部分,但没有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM