python - 属性错误 : Unknown property legend in seaborn

标签 python pandas matplotlib legend seaborn

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 的图例吗?如果是这样,如何做到这一点?

最佳答案

像这里一样使用 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

关于python - 属性错误 : Unknown property legend in seaborn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38131062/

相关文章:

python - Matplotlib 中是否有返回所有单个字母颜色的函数?

python - 从 pyplot 绘图中删除以前绘制的内容

python - 高斯函数python

Python timeit问题

python - wxPython 和高速公路 websockets

python - 如果第一个函数失败,则应用第二个函数

python - 如何在获取历史汇率的同时加快货币兑换速度

python - Pandas 对现有索引进行重采样

python - twinx 轴的 matplotlib axes.clear() 不清除第二个 y 轴标签

python - 线性模型文本分类中的特征重要性,StandardScaler(with_mean=False) 是或否