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)
x = np.arange(0, 150)
ax1.fill_between(x[:long], conf_intveral[0][:long], conf_intveral[1][:long], color='deepskyblue', alpha=1)
4.視覺化結果