matplotlib设置温度折线图
读取温度
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font_set = FontProperties(fname=r"/System/Library/Fonts/STHeiti Medium.ttc", size=15)
import csv
import matplotlib.pyplot as plt
filename = ‘/Users/taojiamin/Desktop/源代码文件/chapter_16/the_csv_file_format/revisions_printing_4/data/sitka_weather_2018_simple.csv’
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
#从文件中获取最高温度
highs=[]
for row in reader:
high = int(row[5])
highs.append(high)
print(highs)
绘制最高温度图形(中文无法显示问题仍然没有解决)
plt.style.use(‘seaborn’)
fig, ax = plt.subplots()
ax.plot(highs, c=‘red’)
#设置图形格式
ax.set_title(“2018年每日最高温度”,fontsize=24)
ax.set_xlabel(‘’,fontsize=16)
ax.set_ylabel(“温度(F)”,fontsize=16)
ax.tick_params(axis=‘both’,which=‘major’,labelsize=16)
plt.show()