属性错误:seaborn中未知的财产传奇

2024-05-16 21:20:37 发布

您现在位置:Python中文网/ 问答频道 /正文

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)

enter image description here

在这种情况下,传说是相当小的,每天都显示不同的色调。不过,我想删除这个传说。

通常,一个包含参数legend=False。但是,对于stripplot,这似乎会输出一个属性错误:

AttributeError: Unknown property legend

可以删除stripplots的图例吗?如果是,怎么做?


Tags: 函数httpssoftwareseabornaxhuetotaledu
1条回答
网友
1楼 · 发布于 2024-05-16 21:20:37

使用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()

enter image description here

相关问题 更多 >