Python 从Seaborn散点图中删除两个传说中的一个
使用“提示”数据集作为玩具模型,我生成以下绘图:Python 从Seaborn散点图中删除两个传说中的一个,python,pandas,matplotlib,seaborn,Python,Pandas,Matplotlib,Seaborn,使用“提示”数据集作为玩具模型,我生成以下绘图: import seaborn as sns import matplotlib.pyplot as plt tips = sns.load_dataset("tips") cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True) g = sns.scatterplot(x="total_bill", y="sex", hue="smoker", size = 'tip',size
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
g = sns.scatterplot(x="total_bill", y="sex", hue="smoker", size = 'tip',sizes=(320, 600), data=tips)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., fontsize=13)
plt.show(g)
这张照片正是我需要的。但是,我想从图例中删除size='tip'
,只保留吸烟者。基本上,删除标记为0.0到12.0的黑色圆圈。如何确保我的图例只有一个可供选择的变量
我能够通过索引图例中的标签找到修复方法
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
g = sns.scatterplot(x="total_bill", y="sex", hue="smoker", size = 'tip',sizes=(320, 600), data=tips)
h,l = g.get_legend_handles_labels()
plt.legend(h[0:3],l[0:3],bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., fontsize=13)
plt.show(g)
我能够通过索引图例中的标签找到修复方法
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
g = sns.scatterplot(x="total_bill", y="sex", hue="smoker", size = 'tip',sizes=(320, 600), data=tips)
h,l = g.get_legend_handles_labels()
plt.legend(h[0:3],l[0:3],bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., fontsize=13)
plt.show(g)