Python 避免在Swarmlot覆盖的seaborn箱线图中重复出现图例

Python 避免在Swarmlot覆盖的seaborn箱线图中重复出现图例,python,matplotlib,seaborn,swarmplot,Python,Matplotlib,Seaborn,Swarmplot,在下面基于seaborn的图中,我正在制作一个盒子图,上面覆盖着一个swarm图。两者都是色调的子集。我有没有办法不让他们在传说中重复两次 这是我的密码: ax = sns.boxplot(x=name_xaxis, y=name_col, hue=hue, data=frame, palette='Set2', linewidth=1.5, width=0.5) sns.swarmplot(x=name_xaxis, y=name_col, hue=hue, data=frame, palet

在下面基于seaborn的图中,我正在制作一个盒子图,上面覆盖着一个swarm图。两者都是色调的子集。我有没有办法不让他们在传说中重复两次

这是我的密码:

ax = sns.boxplot(x=name_xaxis, y=name_col, hue=hue, data=frame, palette='Set2', linewidth=1.5, width=0.5)
sns.swarmplot(x=name_xaxis, y=name_col, hue=hue, data=frame, palette='Set2', color='.25', split=True)

尝试在sns.swarmlot(…)之后添加此项。:


这将用现有图例中的两个条目替换图例。

你真是个该死的图例!我希望每次我偶然发现这个答案时都能重新投票!
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles[:2], labels[:2])