你还可以尝试在一个图表呈现这两个数据集

#compare_DeathValley_and_Sitka_weather.py
#__author__ = 'Liu Shao Ji'
#encoding=utf-8
import csv
from datetime import datetime
from matplotlib.pyplot import MultipleLocator
import matplotlib.pyplot as plt
from C16.try_page_324.try_16_2_2.read_data import read_excel_temp
from C16.try_page_324.try_16_2_2.draw_map import data_draw_map
file_name_1= "death_valley_2014.csv"
file_name_2= "sitka_weather_2014.csv"DeathValley_Data=read_excel_temp(file_name_1)
DeathValley_weather_Data=DeathValley_Data.get_dates_high_low()Sitka_Data=read_excel_temp(file_name_2)
Sitka_weather_Data=Sitka_Data.get_dates_high_low()# print("死亡谷")
#
# print(DeathValley_weather_Data[0])#日期
# print(DeathValley_weather_Data[1])#最高温度
# print(DeathValley_weather_Data[2])#最低温度
# print(DeathValley_weather_Data[3])#表头
#
# print("锡特卡")
#
# print(Sitka_weather_Data[0])#日期
# print(Sitka_weather_Data[1])#最高温度
# print(Sitka_weather_Data[2])#最低温度
# print(Sitka_weather_Data[3])#表头obj_list=[]
obj_list.append(DeathValley_weather_Data)
obj_list.append(Sitka_weather_Data)
print("包含两个城市天气的数据放在obj_list中\n")
print(obj_list)
print(obj_list[0])
print(obj_list[1])
# def __init__(self,header_row,dates,highs,lows,title):
# draw_map=data_draw_map(DeathValley_weather_Data[3],
#                        DeathValley_weather_Data[0],
#                        DeathValley_weather_Data[1],
#                        DeathValley_weather_Data[2],
#                        "Compare DethValley and Sitka Weather")
# draw_map.draw_map()
print("尝试解释obj_list:\n")
draw_map=data_draw_map(obj_list,DeathValley_weather_Data[3],"two city weather compare")
# draw_map.circle_list()
draw_map.draw_map()
#read_data.py
#__author__ = 'Liu Shao Ji'
#encoding=utf-8
import csv
from datetime import datetime
#用于设置y轴的范围
from matplotlib.pyplot import MultipleLocator
import matplotlib.pyplot as pltclass read_excel_temp():def __init__(self,file_name):self.file_name=file_namedef get_dates_high_low(self):filename=self.file_namewith open(filename) as f:reader= csv.reader(f)"""虽然灰色看似没有调用,header_row=next(reader)这行不能注释掉"""header_row=next(reader)'''两个列表,其中一个放什么呢?'''dates,highs,lows=[],[],[]for row in reader:try:current_date=datetime.strptime(row[0],"%Y-%m-%d")high=int(row[1])low=int(row[3])#华氏转摄氏high_c=(float(row[1])-32)/1.8low_c=(float(row[3])-32)/1.8except ValueError:print(current_date,'missing data')else:dates.append(current_date)highs.append(high_c)lows.append(low_c)return(dates,highs,lows,header_row)
file_name= "death_valley_2014.csv"
sample=read_excel_temp(file_name)
dates_and_highs_and_lows=sample.get_dates_high_low()
print(dates_and_highs_and_lows[0])#日期
print(dates_and_highs_and_lows[1])#最高温度
print(dates_and_highs_and_lows[2])#最低温度
print(dates_and_highs_and_lows[3])#表头

#draw_map.py

#__author__ = 'Liu Shao Ji'
#encoding=utf-8
import csv
from datetime import datetime
#用于设置y轴的范围
import random
from matplotlib.pyplot import MultipleLocator
import matplotlib.pyplot as plt
class data_draw_map():#接受一个列表# def __init__(self,header_row,dates,highs,lows,title):#     self.header_row=header_row#     self.dates=dates#     self.highs=highs#     self.lows=lows#     self.title=title#     # print(Sitka_weather_Data[0])#日期#     # print(Sitka_weather_Data[1])#最高温度#     # print(Sitka_weather_Data[2])#最低温度#     # print(Sitka_weather_Data[3])#表头def __init__(self,data_list,header_row,title):self.data_list=data_listself.header_row=header_rowself.title=title# def circle_list(self):#     objs=self.list#     for o in objs:#         dates=o[0]#         highs=o[1]#         lows=o[2]#         header_row=o[3]#         print(dates)#         print(highs)#         print(lows)#         print(header_row)def random_color(self):list_number=list(range(0,101))a=random.choice(list_number)b=a/100return bdef draw_map(self):for index,column_header in enumerate(self.header_row):print(index,column_header)"""根据数据绘制气温图表"""fig = plt.figure(dpi=128,figsize=(10,6))'''321'''"""生成随机颜色"""print("死亡谷日期:"+str(self.data_list[0][0]))print("死亡谷高温:"+str(self.data_list[0][1]))print("死亡谷低温:"+str(self.data_list[0][2]))plt.plot(self.data_list[0][0],self.data_list[0][1],c=(1,self.random_color(),self.random_color()),alpha=0.5)plt.plot(self.data_list[0][0],self.data_list[0][2],c=(1,self.random_color(),self.random_color()),alpha=0.5)plt.plot(self.data_list[1][0],self.data_list[1][1],c=(self.random_color(),1,self.random_color()),alpha=0.5)plt.plot(self.data_list[1][0],self.data_list[1][2],c=(self.random_color(),1,self.random_color()),alpha=0.5)plt.fill_between(self.data_list[0][0],self.data_list[0][1],self.data_list[0][2],facecolor=(1,self.random_color(),self.random_color()),alpha=0.3)plt.fill_between(self.data_list[1][0],self.data_list[1][1],self.data_list[1][2],facecolor=(self.random_color(),1,self.random_color()),alpha=0.3)# title="Daily high temperatures,-2014\nDeath Valley,CA"plt.title(self.title,fontsize=24)plt.xlabel('',fontsize=16)fig.autofmt_xdate()plt.ylabel("Temperature(C)",fontsize=16)plt.tick_params(axis='both',which='major',labelsize=10)#y轴的刻度y_major_locator=MultipleLocator(5)ax=plt.gca()ax.yaxis.set_major_locator(y_major_locator)plt.ylim(-10,50)plt.show()

2020-10-05 Python编程从入门到实践 第16章 下载数据 动手试一试 16-2 比较锡特卡和死亡谷的气温 习题练习相关推荐

  1. Python编程从入门到实践第五章部分习题

    Python编程从入门到实践第五章部分习题 5-8 5-9` names = ['admin','zhang','li','zhao','song'] for name in names:if nam ...

  2. Python编程:从入门到实践 第三章--函数

    Python编程:从入门到实践 第三章-函数 语法 就还是需要先记一下函数定义的语法: def Test(num):num = 12 如上,def func_name(factors): # code ...

  3. 读书笔记——《Python编程从入门到实践》第二章

    读书笔记--<Python编程从入门到实践>第二章 读书笔记--<Python编程从入门到实践>第二章 变量 如何使用变量 如何规范变量命名 字符串 字符串是什么 如何修改字符 ...

  4. python编程从入门到实践 第18章Django入门 2022年最新

    说明:这篇文章只是记录自己自学本书的一个痕迹,日后来看作为一个念想.至于做为公开,是希望对一些同样跟我一样的朋友有一点点帮助,当然我本人就是小白,帮助可能也不大哈哈. 这篇文章记录了<pytho ...

  5. python从入门到实践电子版-Python编程从入门到实践PDF电子书免费下载

    本书是一本针对所有层次的 Python 读者而作的 Python 入门书.全书分两部分 :第一部分介绍用 Python 编程所必须了解的基本概念,包括 matplotlib.NumPy 和 Pygal ...

  6. Python编程 从入门到实践——第1章 起步

    第一章 起步 1.1 搭建编程环境 1.1.1 Python版本 1.1.2 运行Python代码片段 1.1.3 Sublime Text简介 1.2 在不同操作系统中搭建Python编程环境 1. ...

  7. Python编程从入门到实践 -----第4章、操作列表(课后习题答案)

    4-1 比萨:想出至少三种你喜欢的比萨,将其名称储存在一个列表中,在使用循环将每种比萨名称都打印出来. 修改这个for循环,使其打印包含比萨名称的句子,而不是仅仅是比萨的名称,对于每种比萨,都显示一行 ...

  8. Python编程:从入门到实践-第七章:用户输入和while循环(语法)

    #7-1 汽车租赁:编写一个程序,询问用户要租赁什么样的汽车,并打印一条消息,如"Let me see if I can find you a Subaru". ''' print ...

  9. Python编程从入门到实践 -----第3章、列表简介(课后习题答案)

    3-1 姓名: 将一些朋友的姓名存储在一个列表中,并将其命名为names .依次访问该列表中的每个元素,从而将每个朋友的姓名都打印出来. names = ['chen', 'x', 'l']print ...

  10. Python编程从入门到实践第7章习题答案

    #7-1汽车租赁 #coding:gbk #7-1汽车租赁 sorts = input("Please enter the kind of the car") print('Let ...

最新文章

  1. 学会使用Spring注解
  2. Ubuntu16.04 -- 后台进程Nohup
  3. 无刷电机和有刷电机的详解区别
  4. Ch3101-阶乘分解【数论,质因数分解】
  5. mysql返回yyyy mm dd_怎么把取出mysql数据库中的yyyy-MM-dd日期转成yyyy年MM月dd日格式...
  6. 超赞!arXiv论文如何一键链接解读视频,这个浏览器扩展帮你实现
  7. 商业智能在公安交通管理领域的应用
  8. 倒排索引Inverted index
  9. Internet Download Manager v6.41 Build 2
  10. 【word论文排版教程1】页面设置
  11. 189邮箱smpt服务器,189邮箱登录(常用邮箱客户端设置指南)
  12. Android Studio 中集成 ASSIMP
  13. 智能优化及其相关算法
  14. Vistor(访问者模式)行为型
  15. java ppt控件_Java版PPT操作控件Spire.Presentation v2.12.2新版来袭!支持获取具有超链接的目标幻灯片...
  16. Error while adding the mapper ‘interface xx.xx.xxx.xxxx.xxxx.xxxxxxx‘ to configuration.
  17. java零钱换整程序_零钱兑换 Java
  18. 浏览器趋势2014年6月:Chrome的崛起仍在继续
  19. 图解LeetCode——1184. 公交站间的距离(难度:简单)
  20. Python(24)python中的calendar模块(日历模块)

热门文章

  1. 计算机研究生哪个子专业最容易考公务员
  2. Java中涉及到和金钱有关的属性的类型
  3. Spring涉及到的9种设计模式
  4. 【Codecs系列】CABAC熵编码详解
  5. Java邮箱正则匹配
  6. 信创办公--基于WPS的Word最佳实践系列(解决Word兼容性问题)
  7. 断言(C++大师Andrei Alexandrescu的文章)
  8. 主角把异能开发计算机,不容错过的超能力游戏,最厉害的甚至能操控时间!
  9. 浅谈无线AP、无线路由器
  10. python父亲节礼物_父亲节有什么礼物可以推荐?