pandas AttributeError:seaborn 中的未知属性图例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38131062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AttributeError: Unknown property legend in seaborn
提问by ShanZhengYang
The seaborn stripplot has a function which allows hue
.
seaborn stripplot 有一个功能,允许hue
.
Using the example from https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.stripplot.html
使用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.
在这种情况下,图例很小,每天显示不同的色调。但是,我想删除图例。
Normally, one includes a parameter legend=False
. However, for stripplot
, this appears to output an attribute error:
通常,一个包含参数legend=False
。但是,对于stripplot
,这似乎输出了一个属性错误:
AttributeError: Unknown property legend
Can one remove the legend for stripplots
? If so, how does one do this?
可以删除图例stripplots
吗?如果是这样,如何做到这一点?
回答by Serenity
Use ax.legend_.remove()
like here:
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()