Remove seaborn lineplot legend title

对着背影说爱祢 提交于 2019-11-30 06:53:13

Indeed, seaborn is misusing a legend label as a (subgroup-)title. Hence the idea can be to either remove this label, or replace it with custom text.

Replacing with custom text:

legend = ax.legend()
legend.texts[0].set_text("Whatever else")

Removing the label:

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles=handles[1:], labels=labels[1:])

After having removed the label you may of course still set another (real) title:

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles=handles[1:], labels=labels[1:], title="Whatever else")

Extending ImportanceOfBeingErnest answer:

I had the same problem, but the 'Removing the label' example removed the title and first item from the actual legend.

handles, labels = ax.get_legend_handles_labels() ax.legend(handles=handles[1:], labels=labels[1:])

So this removes just the legend title

ax.legend(handles=handles[0:], labels=labels[0:])

(I can't comment so adding this as answer)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!