使用seaborn绘制回归曲线,设置图例

import numpy as np
import os
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from scipy import stats


plt.plot(data_fx, data_fx, label='Reference Line', color='red')
sns.regplot(x=data_fx, y=pred_fx, marker='+', label='Distribution Dots', truncate=False, line_kws={'label': 'Regression Line'})

r, p = stats.pearsonr(data_fx, pred_fx)


# info_dict = {'Label': data_fx, 'Prediction': pred_fx}
# info_df = pd.DataFrame(info_dict)
# h = sns.jointplot(x='Label', y='Prediction', data=info_df, kind='hist')


plt.title(f'All data\nPearson correlation coefficient: {r:.2f}')

plt.xlabel('Label')
plt.ylabel('Prediction')
# # sns.histplot(b, color='blue', label='pred')
# # sns.histplot(a, color='yellow', label='label')
plt.legend(loc='best')
plt.show()

需要注意的是,绘制回归曲线有很多种函数可以选择,但大部分是figure level的函数,不方便修改图例
regplot的图例是试出来的,太难画了
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值