我正在使用seaborn并希望生成一个盒子图,其中所有盒子都具有相同的颜色。出于某种原因,seaborn为每个盒子使用不同的颜色,并且没有选项来停止这种行为并为所有盒子设置相同的颜色。
我怎样才能强迫seaborn为所有盒子使用相同的颜色?
fig, ax = plt.subplots(figsize=(10, 20))
sns.boxplot(y='categorical_var', x='numeric_var', ax=ax)
答案 0 :(得分:5)
使用color
参数:
import seaborn as sns
tips = sns.load_dataset("tips")
sns.boxplot(x="day", y="tip", data=tips, color="seagreen")
答案 1 :(得分:2)
制作自己的调色板并设置框的颜色,如:
# Declare all labels that you want the model to learn
# Using classes learnt by labelEncoder for this
# In any calls to `partial_fit()`, all labels should be from this array only
all_classes = le.transform(le.classes_)
# Notice the parameter classes here
# It needs to present first time
clf2.partial_fit(tfidf, labels, classes=all_classes)
print(clf2.predict(tfidf))
# [0 2 1]
# classes is not present here
clf2.partial_fit(new_tfidf, new_labels)
print(clf2.predict(new_tfidf))
# [1 0 2]
另一种方法是迭代箱形图的艺术家,并为每个轴线艺术家设置import seaborn as sns
import matplotlib.pylab as plt
sns.set_color_codes()
tips = sns.load_dataset("tips")
pal = {day: "b" for day in tips.day.unique()}
sns.boxplot(x="day", y="total_bill", data=tips, palette=pal)
plt.show()
的颜色:
set_facecolor