Python学习笔记(十三)

十六章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)]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值