import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
penguins = sns.load_dataset('penguins')
sns.catplot(data = penguins, x='island', kind='count')
plt.show()
如你所见,我只有蓝色条。我尝试过
sns.reset_orig()
并设置其他 Matplotlib 调色板。似乎没有什么能给我超过一种颜色。
我有
Seaborn version : 0.13.2
和 Matplotlib version : 3.7.1
,我也在 MacBook 上。
请帮忙...我如何获得默认的彩虹色?
Seaborn 对于分类图的默认行为是使用单一颜色。要使用彩虹般的颜色或您选择的颜色,您可以使用
hue
参数。
所以在这一行中,你可以这样做:
sns.catplot(data = penguins, x='island', kind='count', hue='island', palette='rainbow')
这将为每个类别栏生成不同的颜色。您还可以更改
palette
参数以满足您的喜好。希望这有帮助。