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 多平台发布

猜你喜欢

转载自blog.csdn.net/wlh2067/article/details/128927607
今日推荐