python csv文件画图

import csv 
import matplotlib.pyplot as plt
import time 
current_date = time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time()))
print(current_date)
filename = 'map.csv'
with open(filename) as f:
	reader = csv.reader(f)
	header_row = next(reader) #调用了next()一次,因此得到的是文件的第一行
	print(header_row) 
	
	step = []
	mAP = []
	answer = []
	hand = []
	write = []
	sleep = []
	listen = []
	for row in reader:
		step.append(row[1]) 
		mAP.append(row[2])
		answer.append(row[3]) 
		hand.append(row[4])
		write.append(row[5])
		sleep.append(row[6])
		listen.append(row[7])
# 根据数据绘制图形
plt.subplot(211)
plt.title("SSD", fontsize=24)
plt.plot(step,mAP,c='red',label='MAP')
plt.xlabel('step') 
plt.ylabel("mAP")
plt.subplot(212)
'''
#循环画好多条
y =[]
y=[answer ,hand ,write ,sleep ,listen ]
cnames = ['answer','hand','write','sleep','listen']
for a in range(5):    
	colors  = ["blue","red","coral","green","yellow"]  #,"orange"]   
	print(y[a])  
	plt.plot(step,y[a],color=colors[a],label=cnames[a])
'''
#任意挑选画几条
plt.plot(step,answer,color='blue',label='answer')
plt.plot(step,sleep,color='green',label='sleep')
# 设置图形的格式
plt.xlabel('step') 
plt.ylabel("mAP") 
plt.show()

 

你可能感兴趣的:(Python基本操作,Python)