更改海运散点图中的图例位置和标签 [英] Change legend location and labels in Seaborn scatter plot

查看:35
本文介绍了更改海运散点图中的图例位置和标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要更改我的图例在海运散点图中的位置和标签。以下是我的代码:

ax_total_message_ratio=sns.scatterplot(x='total_messages', y='email_messages_ratio',hue='poi',data=df_new)
ax_total_message_ratio.set_title("Email Messages Ratio vs. Total Messages Across Poi",y=1.12,fontsize=20,fontweight='bold')
ax_total_message_ratio.set_ylabel('Email Messages Ratio')
ax_total_message_ratio.set_xlabel('Total Messages')
ax_total_message_ratio.legend.loc("lower right")
put.show()

但我收到以下错误消息; 'function' object has no attribute 'loc'。我能得到一些关于如何控制希伯伦传奇的帮助吗?此外,我还需要在图例标签中将0替换为No,将1替换为Yes。谢谢

推荐答案

您可以使用调用legend()中的loc关键字调整位置,Like

ax_total_message_ratio.legend(loc="lower right")

要包括标记的自定义标签,您可以创建自定义图例,即

import matplotlib.pyplot as plt
from matplotlib.lines import Line2D

custom = [Line2D([], [], marker='.', color='b', linestyle='None'),
          Line2D([], [], marker='.', color='r', linestyle='None')]

fig = plt.figure(figsize=(8,5))

plt.legend(custom, ['Yes', 'No'], loc='lower right')
plt.show()

这将为您提供

删除自动生成的图例,仅保留自定义图例。

这篇关于更改海运散点图中的图例位置和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆