python繪制淺色范圍曲線的示例代碼
直接上效果圖:

上代碼:
import re
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import shutil
import os
import math
sns.set_style('whitegrid')
path=r"F:\pycharm\class\20211008\alexnet_7class_srcData.csv"#數(shù)據(jù)的路徑
#讀取csv文件
csvfile = open(path, 'r')
plots = csv.reader(csvfile)
r1=[]
r2=[]
r3=[]
#將每一列數(shù)據(jù)表示一組,將數(shù)據(jù)分組存放
#row是按行讀取,每一行有三個(gè)數(shù)據(jù),分別存放
for row in plots:
r1.append(round(float(row[0]),3))
r2.append(round(float(row[1]),3))
r3.append(round(float(row[2]),3))
#求均值
avg=[]
for i in range(len(r1)):
avg.append(round((r1[i]+r2[i]+r3[i])/3,3))
#求方差
var=[]
for i in range(len(r1)):
var.append(((r1[i]-avg[i])**2+(r2[i]-avg[i])**2+(r3[i]-avg[i])**2)/3)
#求標(biāo)準(zhǔn)差
std=[]
for i in range(len(r1)):
std.append(math.sqrt(var[i]))
#通過該公式算出平均值+-標(biāo)準(zhǔn)差的曲線,便于后面范圍曲線的描繪
r1 = list(map(lambda x: x[0]-x[1], zip(avg, std)))
r2 = list(map(lambda x: x[0]+x[1], zip(avg, std)))
plt.rcParams["figure.figsize"] = (15,10)
plt.plot(r1)
plt.plot(r2)
plt.legend(['范圍曲線'],fontsize=30)
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
plt.xlabel('Epoch Number',fontsize=20)
plt.ylabel('Accuracy',fontsize=20)
plt.ylim(0, 20)
plt.show()

#橫坐標(biāo)由于fill_between函數(shù)
x=[]
for i in range(300):
x.append(i+1)
# import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (15,10)
plt.plot(avg)
plt.fill_between(x,r1, r2, color=cm.viridis(0.5), alpha=0.2)
plt.legend(['avg'],fontsize=30)
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
plt.xlabel('Epoch Number',fontsize=20)
plt.ylabel('Accuracy',fontsize=20)
plt.ylim(0, 20)
plt.show()
到此這篇關(guān)于python繪制淺色范圍曲線的文章就介紹到這了,更多相關(guān)python淺色范圍曲線內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python截圖的五個(gè)方法實(shí)例總結(jié)
學(xué)習(xí)一門語言最好的方法便是實(shí)踐,想要拿Python寫一個(gè)截圖工具,下面這篇文章主要給大家介紹了關(guān)于Python截圖的五個(gè)方法,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
Python寫入MySQL數(shù)據(jù)庫(kù)的三種方式詳解
Python 讀取數(shù)據(jù)自動(dòng)寫入 MySQL 數(shù)據(jù)庫(kù),這個(gè)需求在工作中是非常普遍的,主要涉及到 python 操作數(shù)據(jù)庫(kù),讀寫更新等。本文總結(jié)了Python寫入MySQL數(shù)據(jù)庫(kù)的三種方式,需要的可以參考一下2022-06-06
python對(duì)象及面向?qū)ο蠹夹g(shù)詳解
這篇文章主要介紹了python對(duì)象及面向?qū)ο蠹夹g(shù),結(jié)合實(shí)例形式詳細(xì)分析了Python面向?qū)ο笏婕暗念?、?duì)象、方法、屬性等概念與使用技巧,需要的朋友可以參考下2016-07-07
python二分查找搜索算法的多種實(shí)現(xiàn)方法
二分查找,也稱折半查找,是一種效率較高的查找方法,本文主要介紹了python二分查找搜索算法的多種實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03
Python3實(shí)現(xiàn)zip分卷壓縮過程解析
這篇文章主要介紹了Python3實(shí)現(xiàn)zip分卷壓縮過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10
Python numpy.power()函數(shù)使用說明
這篇文章主要介紹了Python numpy.power()函數(shù)使用說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-03-03
python使用Tkinter實(shí)現(xiàn)在線音樂播放器
這篇文章主要為大家詳細(xì)介紹了python使用Tkinter實(shí)現(xiàn)在線音樂播放器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01

