首页 > 解决方案 > 为 seaborn 计数图中的所有条形应用单一颜色

问题描述

以下代码为每个类别提供不同的颜色

import seaborn as sns
sns.set(style="darkgrid")
titanic = sns.load_dataset("titanic")
ax = sns.countplot(x="class", data=titanic)

如何使它们都具有相同的颜色? 在此处输入图像描述

标签: matplotlibseaborn

解决方案


文档

seaborn.countplot(x=None,y=None,hue=None,data=None,order=None,hue_order=None,orient=None,color=None,palette=None,saturation=0.75,dodge=True,ax=无,**kwargs)

函数接受颜色参数,改变它来改变颜色。


推荐阅读