python一鍵繪制帶邊框統(tǒng)計的散點圖

python一鍵繪制帶邊框統(tǒng)計的散點圖

科研繪圖越來越卷,傳統(tǒng)的散點圖已經(jīng)不夠看了
比較推薦這種帶xy軸的統(tǒng)計信息的新型散點圖



那么這要怎么畫呢,讓我們用python試一試:

柱形圖

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

波浪型邊欄

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

核密度型

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

繪制自己的數(shù)據(jù)

seaborn封裝之后,只需要一行代碼就行了
要在圖中添加1:1線、統(tǒng)計信息、修改字體,還要手動設(shè)置

讀取數(shù)據(jù)

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

統(tǒng)計信息

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()

本文由mdnice多平臺發(fā)布

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容