最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python繪制散點(diǎn)密度圖的三種方式詳解

 更新時(shí)間:2022年06月10日 08:42:20   作者:氣象水文科研貓  
散點(diǎn)密度圖是在散點(diǎn)圖的基礎(chǔ)上,計(jì)算了每個(gè)散點(diǎn)周圍分布了多少其他的點(diǎn),并通過顏色表現(xiàn)出來。本文主要介紹了Python繪制散點(diǎn)密度圖的三種方式,需要的可以參考下

方式一

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import gaussian_kde
from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib import rcParams
config = {"font.family":'Times New Roman',"font.size": 16,"mathtext.fontset":'stix'}
rcParams.update(config)
# 讀取數(shù)據(jù)
import pandas as pd
filename=r'F:/Rpython/lp37/testdata.xlsx'
df2=pd.read_excel(filename)#讀取文件
x=df2['data1'].values
y=df2['data2'].values
xy = np.vstack([x,y])
z = gaussian_kde(xy)(xy)
idx = z.argsort()
x, y, z = x[idx], y[idx], z[idx]
fig,ax=plt.subplots(figsize=(12,9),dpi=100)
scatter=ax.scatter(x,y,marker='o',c=z,edgecolors='',s=15,label='LST',cmap='Spectral_r')
cbar=plt.colorbar(scatter,shrink=1,orientation='vertical',extend='both',pad=0.015,aspect=30,label='frequency') #orientation='horizontal'
font3={'family':'SimHei','size':16,'color':'k'}
plt.ylabel("估計(jì)值",fontdict=font3)
plt.xlabel("預(yù)測(cè)值",fontdict=font3)
plt.savefig('F:/Rpython/lp37/plot70.png',dpi=800,bbox_inches='tight',pad_inches=0)
plt.show()

方式二

from statistics import mean
import matplotlib.pyplot as plt
from sklearn.metrics import explained_variance_score,r2_score,median_absolute_error,mean_squared_error,mean_absolute_error
from scipy import stats
import numpy as np
from matplotlib import rcParams
config = {"font.family":'Times New Roman',"font.size": 16,"mathtext.fontset":'stix'}
rcParams.update(config)
def scatter_out_1(x,y): ## x,y為兩個(gè)需要做對(duì)比分析的兩個(gè)量。
    # ==========計(jì)算評(píng)價(jià)指標(biāo)==========
    BIAS = mean(x - y)
    MSE = mean_squared_error(x, y)
    RMSE = np.power(MSE, 0.5)
    R2 = r2_score(x, y)
    MAE = mean_absolute_error(x, y)
    EV = explained_variance_score(x, y)
    print('==========算法評(píng)價(jià)指標(biāo)==========')
    print('BIAS:', '%.3f' % (BIAS))
    print('Explained Variance(EV):', '%.3f' % (EV))
    print('Mean Absolute Error(MAE):', '%.3f' % (MAE))
    print('Mean squared error(MSE):', '%.3f' % (MSE))
    print('Root Mean Squard Error(RMSE):', '%.3f' % (RMSE))
    print('R_squared:', '%.3f' % (R2))
    # ===========Calculate the point density==========
    xy = np.vstack([x, y])
    z = stats.gaussian_kde(xy)(xy)
    # ===========Sort the points by density, so that the densest points are plotted last===========
    idx = z.argsort()
    x, y, z = x[idx], y[idx], z[idx]
    def best_fit_slope_and_intercept(xs, ys):
        m = (((mean(xs) * mean(ys)) - mean(xs * ys)) / ((mean(xs) * mean(xs)) - mean(xs * xs)))
        b = mean(ys) - m * mean(xs)
        return m, b
    m, b = best_fit_slope_and_intercept(x, y)
    regression_line = []
    for a in x:
        regression_line.append((m * a) + b)
    fig,ax=plt.subplots(figsize=(12,9),dpi=600)
    scatter=ax.scatter(x,y,marker='o',c=z*100,edgecolors='',s=15,label='LST',cmap='Spectral_r')
    cbar=plt.colorbar(scatter,shrink=1,orientation='vertical',extend='both',pad=0.015,aspect=30,label='frequency')
    plt.plot([0,25],[0,25],'black',lw=1.5)  # 畫的1:1線,線的顏色為black,線寬為0.8
    plt.plot(x,regression_line,'red',lw=1.5)      # 預(yù)測(cè)與實(shí)測(cè)數(shù)據(jù)之間的回歸線
    plt.axis([0,25,0,25])  # 設(shè)置線的范圍
    plt.xlabel('OBS',family = 'Times New Roman')
    plt.ylabel('PRE',family = 'Times New Roman')
    plt.xticks(fontproperties='Times New Roman')
    plt.yticks(fontproperties='Times New Roman')
    plt.text(1,24, '$N=%.f$' % len(y), family = 'Times New Roman') # text的位置需要根據(jù)x,y的大小范圍進(jìn)行調(diào)整。
    plt.text(1,23, '$R^2=%.3f$' % R2, family = 'Times New Roman')
    plt.text(1,22, '$BIAS=%.4f$' % BIAS, family = 'Times New Roman')
    plt.text(1,21, '$RMSE=%.3f$' % RMSE, family = 'Times New Roman')
    plt.xlim(0,25)                                  # 設(shè)置x坐標(biāo)軸的顯示范圍
    plt.ylim(0,25)                                  # 設(shè)置y坐標(biāo)軸的顯示范圍
    plt.savefig('F:/Rpython/lp37/plot71.png',dpi=800,bbox_inches='tight',pad_inches=0)
    plt.show()

方式三

import pandas as pd
import numpy as np
from scipy import optimize
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import Normalize
from scipy.stats import gaussian_kde
from matplotlib import rcParams
config={"font.family":'Times New Roman',"font.size":16,"mathtext.fontset":'stix'}
rcParams.update(config)
# 讀取數(shù)據(jù)
filename=r'F:/Rpython/lp37/testdata.xlsx'
df2=pd.read_excel(filename)#讀取文件
x=df2['data1'].values.ravel()
y=df2['data2'].values.ravel()
N = len(df2['data1'])
#繪制擬合線
x2 = np.linspace(-10,30)
y2 = x2
def f_1(x,A,B):
    return A*x + B
A1,B1 = optimize.curve_fit(f_1,x,y)[0]
y3 = A1*x + B1
# Calculate the point density
xy = np.vstack([x,y])
z = gaussian_kde(xy)(xy)
norm = Normalize(vmin = np.min(z), vmax = np.max(z))
#開始繪圖
fig,ax=plt.subplots(figsize=(12,9),dpi=600)
scatter=ax.scatter(x,y,marker='o',c=z*100,edgecolors='',s=15,label='LST',cmap='Spectral_r')
cbar=plt.colorbar(scatter,shrink=1,orientation='vertical',extend='both',pad=0.015,aspect=30,label='frequency')
cbar.ax.locator_params(nbins=8)
cbar.ax.set_yticklabels([0.005,0.010,0.015,0.020,0.025,0.030,0.035])#0,0.005,0.010,0.015,0.020,0.025,0.030,0.035
ax.plot(x2,y2,color='k',linewidth=1.5,linestyle='--')
ax.plot(x,y3,color='r',linewidth=2,linestyle='-')
fontdict1 = {"size":16,"color":"k",'family':'Times New Roman'}
ax.set_xlabel("PRE",fontdict=fontdict1)
ax.set_ylabel("OBS",fontdict=fontdict1)
# ax.grid(True)
ax.set_xlim((0,25))
ax.set_ylim((0,25))
ax.set_xticks(np.arange(0,25.1,step=5))
ax.set_yticks(np.arange(0,25.1,step=5))
plt.savefig('F:/Rpython/lp37/plot72.png',dpi=800,bbox_inches='tight',pad_inches=0)
plt.show()

到此這篇關(guān)于Python繪制散點(diǎn)密度圖的三種方式詳解的文章就介紹到這了,更多相關(guān)Python散點(diǎn)密度圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python實(shí)現(xiàn)redis三種cas事務(wù)操作

    python實(shí)現(xiàn)redis三種cas事務(wù)操作

    本篇文章主要介紹了python實(shí)現(xiàn)redis三種cas事務(wù)操作,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-12-12
  • ?分享一個(gè)Python?遇到數(shù)據(jù)庫(kù)超好用的模塊

    ?分享一個(gè)Python?遇到數(shù)據(jù)庫(kù)超好用的模塊

    這篇文章主要介紹了?分享一個(gè)Python?遇到數(shù)據(jù)庫(kù)超好用的模塊,SQLALchemy這個(gè)模塊,該模塊是Python當(dāng)中最有名的ORM框架,該框架是建立在數(shù)據(jù)庫(kù)API之上,使用關(guān)系對(duì)象映射進(jìn)行數(shù)據(jù)庫(kù)的操作,,需要的朋友可以參考下
    2022-04-04
  • 用python寫個(gè)自動(dòng)SSH登錄遠(yuǎn)程服務(wù)器的小工具(實(shí)例)

    用python寫個(gè)自動(dòng)SSH登錄遠(yuǎn)程服務(wù)器的小工具(實(shí)例)

    下面小編就為大家?guī)硪黄胮ython寫個(gè)自動(dòng)SSH登錄遠(yuǎn)程服務(wù)器的小工具(實(shí)例)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06
  • Django執(zhí)行源生mysql語句實(shí)現(xiàn)過程解析

    Django執(zhí)行源生mysql語句實(shí)現(xiàn)過程解析

    這篇文章主要介紹了Django執(zhí)行源生mysql語句實(shí)現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11
  • 詳解python tkinter包獲取本地絕對(duì)路徑(以獲取圖片并展示)

    詳解python tkinter包獲取本地絕對(duì)路徑(以獲取圖片并展示)

    這篇文章主要給大家介紹了關(guān)于python tkinter包獲取本地絕對(duì)路徑(以獲取圖片并展示)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • 解決python和pycharm安裝gmpy2 出現(xiàn)ERROR的問題

    解決python和pycharm安裝gmpy2 出現(xiàn)ERROR的問題

    這篇文章主要介紹了python和pycharm安裝gmpy2 出現(xiàn)ERROR的解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • 最新評(píng)論

    天镇县| 阿勒泰市| 夏邑县| 富裕县| 普洱| 甘孜县| 普陀区| 子长县| 勐海县| 双城市| 丘北县| 专栏| 临湘市| 思茅市| 松桃| 浏阳市| 额尔古纳市| 凌海市| 浦城县| 阳江市| 泽库县| 海阳市| 定陶县| 娄底市| 蒙自县| 永福县| 竹溪县| 汨罗市| 温泉县| 阿图什市| 永年县| 芦溪县| 呼伦贝尔市| 朝阳区| 福泉市| 弋阳县| 本溪| 常山县| 柞水县| 民权县| 永春县|