seaborn - 如何在 regplot 中将传奇艺术家从点更改为线?
问题描述
我有一个带有回归线的 regplot。当我添加图例时,图例的标签是一个点。如何更改为点到线?
ax = sns.regplot(x='chronolgical age', y = i_feature,
data = plot_datai[plot_datai['Sex']==-1], fit_reg=True,
scatter_kws={'alpha':0.8, 's':2}, line_kws={'alpha':0.8, 'linewidth':2},
color = sex_color[0], label = 'Female',
x_jitter = .2, order = 2)
ax = sns.regplot(x='chronolgical age', y = i_feature,
data = plot_datai[plot_datai['Sex']==1], fit_reg=True,
scatter_kws={'alpha':0.8, 's':2}, line_kws={'alpha':0.8, 'linewidth':2},
color = sex_color[1], label = 'Male',
x_jitter = .2, order = 2)
ax.legend(loc = 'lower left', borderpad=.2)
解决方案
可以通过 将 设置为线图,而不是添加label
到regplot
(这似乎将散点图视为其主要组成部分)。label
line_kws
以下是一些使用“提示”数据集以及问题中使用的选项的示例代码:
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
ax = sns.regplot(x="total_bill", y="tip", data=tips[tips["sex"] == "Female"],
fit_reg=True,
scatter_kws={'alpha': 0.8, 's': 2},
line_kws={'alpha': 0.8, 'linewidth': 2, 'label': 'Female'},
color='crimson', # label='Female',
x_jitter=.2, order=2)
ax = sns.regplot(x="total_bill", y="tip", data=tips[tips["sex"] == "Male"],
fit_reg=True,
scatter_kws={'alpha': 0.8, 's': 2},
line_kws={'alpha': 0.8, 'linewidth': 2, 'label': 'Male'},
color='dodgerblue', # label='Male',
x_jitter=.2, order=2)
ax.legend(loc='upper left', borderpad=.2)
plt.show()
推荐阅读
- .net - 尽管证书错误,如何在 .NET Core 中获取 HTTP 响应
- shopify - 使用 Shopify REST API 对取消的订单进行退款
- java - 仅当不同键下的值匹配时,列表中某些 HashMap 值的总和
- python - 如果另一个列表中不存在的列表项如何不更改
- html - 为什么垂直对齐元素总是那么难
- verilog - 注册类型变量给出错误:未知类型
- events - 在 angular7 组件中处理 externaljs DOM 操作
- css - 使用 HTML、CSS、Jquery 在单击 div 时启用禁用按钮?
- java - 如何删除查看寻呼机的特定位置
- ruby-on-rails - Rails 5:Stripe 检索或创建产品