highs_lows.py
import csv from matplotlib import pyplot as plt #从文件中获取最高气温 filename="sitka_weather_07-2014.csv" #文件地址替换为自己的文件地址 with open(filename) as f: reader=csv.reader(f) header_row=next(reader) highs=[] for row in reader: high=int(row[1]) highs.append(high) print(highs) #根据数据绘制图形 fig=plt.figure(dpi=128,figsize=(10,6)) plt.plot(highs,c="red") #设置图形的格式 plt.title("Daily high temperatures,July 2014",fontsize=24) plt.xlabel("",fontsize=16) plt.ylabel("Temperature(F)",fontsize=16) plt.tick_params(axis="both",which="major",labelsize=16)
以上就是python从文件中读取每日最高气温代码 python入门到实践的全部内容,供大家参考。如果觉的这篇文章对你有帮助, 欢迎收藏点赞转发,你也可以在评论区留言,就这个问题进行讨论!