seaborn stripplot 有一个允许 hue
的功能。
使用 https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.stripplot.html 中的示例
import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.stripplot(x=tips["total_bill"])
ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True)
在这种情况下,图例很小,每天显示不同的色调。但是,我想删除图例。
通常,包含一个参数legend=False
。但是,对于 stripplot
,这似乎会输出属性错误:
AttributeError: Unknown property legend
可以删除 stripplots
的图例吗?如果是这样,如何做到这一点?
最佳答案
像这里一样使用 ax.legend_.remove()
:
import seaborn as sns
import matplotlib.pylab as plt
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True)
# remove legend from axis 'ax'
ax.legend_.remove()
plt.show()
关于python - 属性错误 : Unknown property legend in seaborn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38131062/