Ai
1 Star 0 Fork 0

leetone/my_python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
highs_lows.py 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
leetone 提交于 2018-08-15 13:49 +08:00 . 给图表区域着色,加入颜色透明度
import csv
from matplotlib import pyplot as plt
from matplotlib.font_manager import FontProperties
font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=12)
filename = '上海天气.csv'
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
highs,lows,times = [],[],[]
for row in reader:
#1去除掉单位转换为数字;2将华氏温度转换为摄氏温度
high = round((5/9)*(int(row[1][:-1])-32),2)
low = round((5/9)*(int(row[2][:-1])-32),2)
highs.append(high)
lows.append(low)
times.append(row[0])
#print(times)
#根据数据绘制图形
fig = plt.figure(dpi=128,figsize=(11,5))
plt.plot(times,highs,c='red',alpha=0.5)
plt.plot(times,lows,c='blue',alpha=0.5)
plt.fill_between(times,highs,lows,facecolor='green',alpha=0.1)
#倾斜横坐标,防止相邻的数据重叠
fig.autofmt_xdate()
#设置图形格式
plt.title("上海2018-08-14天气",fontproperties=font_set)
plt.xlabel('时间',fontsize=16,fontproperties=font_set)
plt.ylabel("气温(F)",fontsize=16,fontproperties=font_set)
plt.tick_params(axis='both',which='major',labelsize=7)
plt.show()
#打印标题行
#print(header_row)
#for index,column_header in enumerate(header_row):
#print(index,column_header)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/leetone123/my_python.git
git@gitee.com:leetone123/my_python.git
leetone123
my_python
my_python
master

搜索帮助