Python学习记录 | 您所在的位置:网站首页 › matplotlib曲面某点取值变化图 › Python学习记录 |
问题:假设通过爬虫获取了北京2020年3月10月每天白天的最高气温,列表A和B,那么此时如何找出气温随时间(天)变化的规律 url = https://lishi.tianqi.com/beijing/202003.html (数据有一些调整) a=[10,9,8,7,9,10,15,6,11,11,16,14,12,16,18,12,23,27,17,24,17,21,22,18,21,12,13,14,19] b= [33,30,28,30,30,30,31,31,31,26,26,26,27,25,23,26,27,28,29,26,26,26,18,24,25,25,26,26,19,20] # -*- coding: utf-8 -*- from matplotlib import pyplot as plt from matplotlib import font_manager my_font = font_manager.FontProperties(fname='\Windows\Fonts\msyhl.ttc') #与绘制折线图一致,先导入pyplot和font_manager 1. 绘制散点图 - scatter() y3 = [10,9,8,7,9,10,15,6,11,11,16,14,12,16,18,12,23,27,17,24,17,21,22,18,21,12,13,14,19,27,17] y10 = [33,30,28,30,30,30,31,31,31,26,26,26,27,25,23,26,27,28,29,26,26,26,18,18,17,17,16,21,19,18,16] #注意:x = range(1,32) 同时使用一条X轴会重叠数据,需要分别展示3月和10月的结果,设定两个X值 x_3 = range(1,32) #设定3月数据对应的X轴区间 x_10 = range(51,82) #设定10月数据对应的x轴区间 plt.figure(figsize=(20,8),dpi=80) #设定图像大小与清晰度 plt.scatter(x_3,y3,label='三月',color='plum') #直接设定颜色 plt.plot(x_10,y10,label='十月',color = 'navy') #直接设定颜色以上图形中X轴,并没有将3月与10月的数据区分,直接是0-80对应的列表 2. 将点用折线链接 #可以添加折线图将点链接起来 plt.plot(x_3,y3,label='三月',color='plum') plt.plot(x_10,y10,label='十月',color = 'navy')
|
CopyRight 2018-2019 实验室设备网 版权所有 |