AttributeError:Seaborn中的未知属性图例 [英] AttributeError: Unknown property legend in seaborn
本文介绍了AttributeError:Seaborn中的未知属性图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
seaborn条形图具有允许hue
的功能.
The seaborn stripplot has a function which allows 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)
在这种情况下,图例非常小,每天显示不同的色调.但是,我想删除图例.
In this case, the legend is quite small, showing a different hue for each day. However, I would like to remove the legend.
通常,其中包含一个参数legend=False
.但是,对于stripplot
,这似乎会输出属性错误:
Normally, one includes a parameter legend=False
. However, for stripplot
, this appears to output an attribute error:
AttributeError: Unknown property legend
可以删除stripplots
的图例吗?如果是这样,该怎么做?
Can one remove the legend for stripplots
? If so, how does one do this?
推荐答案
在此处使用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()
这篇关于AttributeError:Seaborn中的未知属性图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文