python一键绘制带边框统计的散点图

python一键绘制带边框统计的散点图

科研绘图越来越卷,传统的散点图已经不够看了
比较推荐这种带xy轴的统计信息的新型散点图 alt alt 那么这要怎么画呢,让我们用python试一试:

柱形图

penguins = pd.read_csv('python/seaborn-data-master/penguins.csv')
sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm")
alt

波浪型边栏

sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species")
alt

核密度型

sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species", kind="kde")
alt

绘制自己的数据

seaborn封装之后,只需要一行代码就行了
要在图中添加1:1线、统计信息、修改字体,还要手动设置

读取数据

import pandas as pd
import numpy as np
data = pd.read_csv(r'D:\acad1\data\compare\link1.csv', index_col=0)

统计信息

xlable和ylable是我的列名~

xlable, ylable = "dynCCI","Mean"
from sklearn.metrics import explained_variance_score,r2_score,median_absolute_error,mean_squared_error,mean_absolute_error
x = data[xlable]; y = data[ylable]

BIAS = np.mean(x - y)/np.mean(x)
MSE = mean_squared_error(x, y)
RMSE = np.power(MSE, 0.5)
#R2 = r2_score(x, y)
R2 = np.corrcoef(x,y)[0,1] ** 2
MAE = mean_absolute_error(x, y)
EV = explained_variance_score(x, y)

def slope(xs, ys):
    m = (((np.mean(xs) * np.mean(ys)) - np.mean(xs * ys)) / ((np.mean(xs) * np.mean(xs)) - np.mean(xs * xs)))
    b = np.mean(ys) - m * np.mean(xs)
    return m, b
k, b = slope(x, y)
R2,MAE,BIAS,RMSE,k

绘图

import seaborn as sns
import matplotlib.pyplot as plt
rc = {'font.sans-serif': ['Times New Roman']}
p = sns.jointplot(xlable, ylable, data,kind='reg',xlim=(-50, 1550), ylim=(-50, 1550),height=7, color='#F84B4D')
p.ax_joint.plot([0,1500], [0,1500], 'b-', linewidth = 2, color="#F84B4D")
sns.set(context='notebook', style="darkgrid", font_scale=2, rc=rc)
p.ax_joint.text(0, 1400, '$R^2=%.3f$' % R2, family = 'Times New Roman', size=20)
p.ax_joint.text(0, 1300, '$Bias=%.3f$' % BIAS, family = 'Times New Roman', size=20)
p.ax_joint.text(0, 1200, '$MAE=%.3f$' % MAE, family = 'Times New Roman', size=20)
p.ax_joint.text(0, 1100, '$K=%.3f$' % k, family = 'Times New Roman', size=20)
sns.set(context='notebook', style="darkgrid", font_scale=2, rc=rc)
plt.show()
alt

本文由 mdnice 多平台发布

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

地学万事屋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值