【 BOXPLOT ALL THREE】

# -*- coding: utf-8 -*-
"""
Created on Mon Sep 12 21:59:43 2022

@author: Lenovo
"""

# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
Created on Thu Sep  8 17:28:28 2022

@author: Lenovo
"""

import os
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

path=r'D:\Fluxnet\OUTCOME\RMSE'

drivers12_BIAS=pd.DataFrame()
drivers11_BIAS=pd.DataFrame()
drivers10_BIAS=pd.DataFrame()
drivers9_BIAS=pd.DataFrame()
drivers8_BIAS=pd.DataFrame()
drivers7_BIAS=pd.DataFrame()
drivers6_BIAS=pd.DataFrame()
drivers5_BIAS=pd.DataFrame()
drivers4_BIAS=pd.DataFrame()
drivers3_BIAS=pd.DataFrame()

drivers12_R2=pd.DataFrame()
drivers11_R2=pd.DataFrame()
drivers10_R2=pd.DataFrame()
drivers9_R2=pd.DataFrame()
drivers8_R2=pd.DataFrame()
drivers7_R2=pd.DataFrame()
drivers6_R2=pd.DataFrame()
drivers5_R2=pd.DataFrame()
drivers4_R2=pd.DataFrame()
drivers3_R2=pd.DataFrame()

drivers12_RMSE=pd.DataFrame()
drivers11_RMSE=pd.DataFrame()
drivers10_RMSE=pd.DataFrame()
drivers9_RMSE=pd.DataFrame()
drivers8_RMSE=pd.DataFrame()
drivers7_RMSE=pd.DataFrame()
drivers6_RMSE=pd.DataFrame()
drivers5_RMSE=pd.DataFrame()
drivers4_RMSE=pd.DataFrame()
drivers3_RMSE=pd.DataFrame()

dri12_BIAS=[]
dri11_BIAS=[]
dri10_BIAS=[]
dri9_BIAS=[]
dri8_BIAS=[]
dri7_BIAS=[]
dri6_BIAS=[]
dri5_BIAS=[]
dri4_BIAS=[]
dri3_BIAS=[]

dri12_R2=[]
dri11_R2=[]
dri10_R2=[]
dri9_R2=[]
dri8_R2=[]
dri7_R2=[]
dri6_R2=[]
dri5_R2=[]
dri4_R2=[]
dri3_R2=[]

dri12_RMSE=[]
dri11_RMSE=[]
dri10_RMSE=[]
dri9_RMSE=[]
dri8_RMSE=[]
dri7_RMSE=[]
dri6_RMSE=[]
dri5_RMSE=[]
dri4_RMSE=[]
dri3_RMSE=[]

for a in os.listdir(path):
    
    a=pd.read_csv(os.path.join(path,a))

    dri12_BIAS+=  [a['BIAS'].loc[0]]
    dri11_BIAS+=  [a['BIAS'].loc[0]] 
    dri10_BIAS +=  [a['BIAS'].loc[1]]
    dri9_BIAS  +=  [a['BIAS'].loc[2]]
    dri8_BIAS  +=  [a['BIAS'].loc[3]] 
    dri7_BIAS  +=  [a['BIAS'].loc[4]]
    dri6_BIAS +=  [a['BIAS'].loc[5]]   
    dri5_BIAS  +=  [a['BIAS'].loc[6]] 
    dri4_BIAS  +=  [a['BIAS'].loc[7]]
    dri3_BIAS  +=  [a['BIAS'].loc[8]]

    dri12_R2 +=  [a['R2'].loc[0]]
    dri11_R2 +=  [a['R2'].loc[0]] 
    dri10_R2 +=  [a['R2'].loc[1]]
    dri9_R2  +=  [a['R2'].loc[2]]
    dri8_R2  +=  [a['R2'].loc[3]] 
    dri7_R2  +=  [a['R2'].loc[4]]
    dri6_R2  +=  [a['R2'].loc[5]]   
    dri5_R2  +=  [a['R2'].loc[6]] 
    dri4_R2  +=  [a['R2'].loc[7]]
    dri3_R2  +=  [a['R2'].loc[8]] 

    dri12_RMSE +=  [a['RMSE'].loc[0]]         
    dri11_RMSE +=  [a['RMSE'].loc[0]] 
    dri10_RMSE +=  [a['RMSE'].loc[1]]
    dri9_RMSE  +=  [a['RMSE'].loc[2]]
    dri8_RMSE  +=  [a['RMSE'].loc[3]] 
    dri7_RMSE  +=  [a['RMSE'].loc[4]]
    dri6_RMSE  +=  [a['RMSE'].loc[5]]   
    dri5_RMSE  +=  [a['RMSE'].loc[6]] 
    dri4_RMSE  +=  [a['RMSE'].loc[7]]
    dri3_RMSE  +=  [a['RMSE'].loc[8]]
   

drivers12_BIAS['RF11'] = dri11_BIAS

drivers11_BIAS['RF11'] = dri11_BIAS

drivers10_BIAS['RF10'] = dri10_BIAS

drivers9_BIAS['RF9'] = dri9_BIAS

drivers8_BIAS['RF8'] = dri8_BIAS

drivers7_BIAS['RF7'] = dri7_BIAS

drivers6_BIAS['RF6'] = dri6_BIAS

drivers5_BIAS['RF5'] = dri5_BIAS

drivers4_BIAS['RF4'] = dri4_BIAS

drivers3_BIAS['RF3'] = dri3_BIAS

drivers12_R2['RF11'] = dri11_R2
drivers11_R2['RF11'] = dri11_R2

drivers10_R2['RF10'] = dri10_R2

drivers9_R2['RF9'] = dri9_R2

drivers8_R2['RF8'] = dri8_R2

drivers7_R2['RF7'] = dri7_R2

drivers6_R2['RF6'] = dri6_R2

drivers5_R2['RF5'] = dri5_R2

drivers4_R2['RF4'] = dri4_R2

drivers3_R2['RF3'] = dri3_R2

drivers12_RMSE['RF11'] = dri11_RMSE
drivers11_RMSE['RF11'] = dri11_RMSE

drivers10_RMSE['RF10'] = dri10_RMSE

drivers9_RMSE['RF9'] = dri9_RMSE

drivers8_RMSE['RF8'] = dri8_RMSE

drivers7_RMSE['RF7'] = dri7_RMSE

drivers6_RMSE['RF6'] = dri6_RMSE

drivers5_RMSE['RF5'] = dri5_RMSE

drivers4_RMSE['RF4'] = dri4_RMSE

drivers3_RMSE['RF3'] = dri3_RMSE


#================================plot

fig , axes = plt.subplots(3,1 , figsize=(10,5) , dpi=400 ,sharex=True)

fig.tight_layout()

fig.subplots_adjust(hspace=0)

# sns.set(style='ticks')
sns.set_context(font_scale=3, rc={"lines.linewidth": 1.2})

#=================================BIAS

b_BIAS = pd.concat([drivers12_BIAS,drivers11_BIAS,drivers10_BIAS,drivers9_BIAS
               ,drivers8_BIAS,drivers7_BIAS,drivers6_BIAS
               ,drivers5_BIAS,drivers4_BIAS,drivers3_BIAS]
              ,keys=('RF12','RF11','RF10','RF9','RF8','RF7','RF6','RF5','RF4','RF3'))

b_BIAS=b_BIAS.stack().rename_axis(index=['Legend','nan','LE'])

b_BIAS=b_BIAS.reset_index(level=[0,2],name='BIAS') # reset 重置索引 

ax_bias=sns.boxplot(data=b_BIAS, x='LE',y='BIAS',ax=axes[1], width=0.5)

ax_bias.xaxis.label.set_visible(False)
# ax_bias.yaxis.label.set_visible(False)  # 不显示y轴标签

#=================================R2

b_R2 = pd.concat([drivers12_R2,drivers11_R2,drivers10_R2,drivers9_R2
               ,drivers8_R2,drivers7_R2,drivers6_R2
               ,drivers5_R2,drivers4_R2,drivers3_R2]
              ,keys=('RF12','RF11','RF10','RF9','RF8','RF7','RF6','RF5','RF4','RF3'))

b_R2=b_R2.stack().rename_axis(index=['Legend','nan','LE'])

b_R2=b_R2.reset_index(level=[0,2],name='R²') # reset 重置索引 

ax_r2=sns.boxplot(data=b_R2, x='LE',y='R²',ax=axes[0], width=0.9,hue='Legend') #ax0最上面那个

ax_r2.xaxis.label.set_visible(False)
# ax_r2.yaxis.label.set_visible(False)  # 不显示y轴标签



#=================================RMSE

b_RMSE = pd.concat([drivers12_RMSE,drivers11_RMSE,drivers10_RMSE,drivers9_RMSE
               ,drivers8_RMSE,drivers7_RMSE,drivers6_RMSE
               ,drivers5_RMSE,drivers4_RMSE,drivers3_RMSE]
              ,keys=('RF12','RF11','RF10','RF9','RF8','RF7','RF6','RF5','RF4','RF3'))

b_RMSE=b_RMSE.stack().rename_axis(index=['Legend','nan','LE'])

b_RMSE=b_RMSE.reset_index(level=[0,2],name='RMSE') # reset 重置索引 

ax_rmse=sns.boxplot(data=b_RMSE, x='LE',y='RMSE',ax=axes[2], width=0.5)

# hue='Legend'

ax_rmse.set(xticklabels=[]) 
ax_rmse.tick_params(bottom=False)  # remove the ticks
ax_rmse.set(xlabel=None)  # remove the x-axis label


sns.move_legend(
    ax_r2, "lower center",bbox_to_anchor=(0.5, 1),
      ncol=9, title=None, frameon=False)
# sns.move_legend(
#     ax_bias, "lower center",bbox_to_anchor=(0.5, 2),
#       ncol=9, title=None, frameon=False) 
# sns.move_legend(
#     ax_rmse, "lower center",bbox_to_anchor=(0.5, 3),
      # ncol=9, title=None, frameon=False)  

ax_rmse.xaxis.label.set_visible(False)
# ax_rmse.yaxis.label.set_visible(False)  # 不显示y轴标签


plt.savefig(os.path.join(r'D:\Fluxnet\PIC666\Boxplot','ALL14')
            ,bbox_inches = 'tight')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值