python讀取csv文件數據繪制圖像,例子繪制天氣每天最高最低氣溫氣象圖


 
代碼:
import csv
from matplotlib import pyplot as plt
arr=[]
arrmin=[]
date=[]
with open(r'C:\Users\Administrator\Desktop\新建文本文檔 (3).csv') as cs:
    read=csv.reader(cs)
    header=next(read) #next()函數返回文件的下一行,這里只調用一次就返回第一行,同時因為對read調用了一次next,所以之后的read讀取會從第二行開始
    row=0
 
    for i in read:
       
        arr.append(int(i[0])) #提取csv文件里面的第一列數據
        arrmin.append(int(i[1])) #提取csv文件里面的第二列數據
        date.append(int(i[2])) #提取csv文件里面的第三列數據
print(header)  
print(arr)
print(date)
plt.plot(date,arr,c='yellow')
plt.plot(date,arrmin,c='red')
 
plt.show()
   
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM