python-科研繪圖系列(6)-深度模型準確率,誤差收斂曲線圖;雙座標繪圖;雙座標圖例放置在一個框中;帶95%置信區間的曲線圖

好人就是拉風發表於2020-10-19

1.繪製雙座標


import matplotlib.pyplot as plt
import numpy as np
import  re
from scipy import stats


ax1=fig.add_subplot(1,1, iii)
lns1=ax1.plot(mean[:long], color='darkblue', linewidth=2, linestyle='-',label='ZZZZ Acc')##畫準確率曲線
ax2=ax1.twinx()
lns4=ax2.plot(mean[:long], color='darkolivegreen',  linewidth=2,linestyle='-',label='ZZZZ Loss') #畫損失曲線

2.雙座標圖例放置在一個框中

lns1=ax1.plot(mean[:long], color='darkblue', linewidth=2, linestyle='-',label='ZZZZ Acc')
lns2=ax1.plot(mean[:long], color='orange', linewidth=2, linestyle='-',label='XXXX Acc')
lns3=ax2.plot(mean[:long], color='crimson',  linewidth=2,linestyle='-',label='XXXX Loss')
lns4=ax2.plot(mean[:long], color='darkolivegreen',  linewidth=2,linestyle='-',label='ZZZZ Loss')

lns = lns1 + lns2 + lns3+lns4
labs = [l.get_label() for l in lns]
ax1.legend(lns, labs, loc=0,bbox_to_anchor=(1,1.1),ncol=4,labelspacing=1,columnspacing=0.4,fontsize=16)

3.帶95%置信度曲線

mean, std = np.mean(A, 0), np.std(A, 0)#計算平均值和標準差
lns1=ax1.plot(mean[:long], color='darkblue', linewidth=2, linestyle='-',label='ZZZZ Acc')#畫平均值曲線
conf_intveral = stats.norm.interval(0.95, loc=mean, scale=std)#計算95%的上下區間
x = np.arange(0, 150)
ax1.fill_between(x[:long], conf_intveral[0][:long], conf_intveral[1][:long], color='deepskyblue', alpha=1)#填充區間

4.視覺化結果

在這裡插入圖片描述

相關文章