十六章CSV
ax.set_title等函数中的标题应该使用英文单引号而不是双引号,否则继续输入中文时程序会误以为汉字字体错误。
RuntimeWarning: Glyph 24180 missing from current font. font.set_text(s, 0.0, flags=flags)
其他部分程序运行比较成功
import csv
import matplotlib.pyplot as plt
import matplotlib
from datetime import datetime
filename='D:\\pycharmprograms\\codes\\chapter_16\\the_csv_file_format\\data\\sitka_weather_2018_simple.csv'
with open(filename) as f:
reader=csv.reader(f)
header_row=next(reader)
dates,highs,lows=[],[],[]
for row in reader:
high=int(row[5])
current_date=datetime.strptime(row[2],'%Y-%m-%d')
low=int(row[6])
highs.append(high)
dates.append(current_date)
lows.append(low)
plt.style.use('seaborn')
fig,ax=plt.subplots()
matplotlib.rcParams['font.sans-serif'] = ['KaiTi']
ax.plot(dates,highs,c='red',alpha=0.5)
ax.plot(dates,lows,c='green',alpha=0.5)
ax.fill_between(dates,highs,lows,facecolor='blue',alpha=0.1)
ax.set_title('2018年最高温',fontsize=24)
ax.set_xlabel('',fontsize=16)
fig.autofmt_xdate()
ax.set_ylabel('温度F',fontsize=16)
ax.tick_params(axis='both',which='major',labelsize=16)
plt.show()
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6OvZh7JJ-1611572909019)(https://s3-us-west-2.amazonaws.com/secure.notion-static.com/3047e082-a387-4064-8997-f1d98eae63d4/Untitled.png)]