python matplotlib库绘制散点图例题解析
作者:yaominghui 发布时间:2023-08-14 03:12:56
标签:python,matplotlib,库,绘制,散点图
假设通过爬虫你获取到了北京2016年3,10月份每天白天的最高气温(分别位于列表a,b),那么此时如何寻找出气温随时间(天)变化的某种规律?
a = [11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,22,22,23]
b = [26,26,28,19,21,17,16,19,18,20,20,19,22,23,17,20,21,20,22,15,11,15,5,13,17,10,11,13,12,13,6]
代码实现,基本和绘制折线图实现类似,只有略微差别
from matplotlib import pyplot as plt
import matplotlib
font = {'family': 'MicroSoft YaHei'}
matplotlib.rc('font', **font)
# 三月份和十月份的气温
y_3 = [11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,22,22,23]
y_10 = [26,26,28,19,21,17,16,19,18,20,20,19,22,23,17,20,21,20,22,15,11,15,5,13,17,10,11,13,12,13,6]
x_3 = range(1, 32)
x_10 = range(51, 82)
plt.figure(figsize=(16, 8), dpi=80)
# 使用scatter方法绘制散点图散点图,其它的和之前绘制折线图没有太大区别
plt.scatter(x_3, y_3, label='三月份')
plt.scatter(x_10, y_10, label='十月份')
# 调整x轴的刻度
_x = list(x_3) + list(x_10)
_xtick_labels = ['3月{}号'.format(i) for i in x_3] + ['10月{}号'.format(i-50) for i in x_10]
plt.xticks(_x[::3], _xtick_labels[::3], rotation=45) # 步长为3,旋转45度
# 添加描述信息
plt.xlabel('时间')
plt.ylabel('温度')
plt.title('气温散点图')
plt.legend() # 图例
plt.show() # 展示
效果图
来源:https://www.cnblogs.com/springionic/p/11148625.html
0
投稿
猜你喜欢
- 1.问题背景Python之所以强大,不仅是因为该语言本身的特点,也是因为它拥有众多无所不能的第三方库。强大的软件库允许开发者专注于业务,避免
- 简介壁纸的选择其实很大程度上能看出电脑主人的内心世界,有的人喜欢风景,有的人喜欢星空,有的人喜欢美女,有的人喜欢动物。然而,终究有一天你已经
- 有时候我们在前端开发工作中为了获取图片的信息,需要在图片加载完成后才可以正确的获取到图片的大小尺寸,并且执行相应的回调函数使图片产生某种显示
- 通过logging模块,重写一个logging2模块,独立开启线程,将待写的日志信息异步放入队列,做到日志输出不影响主流程性能,环境pyth
- 课程体系结构:1、Requests框架:自动爬取HTML页面与自动网络请求提交2、robots.txt:网络爬虫排除标准3、Beautifu
- EXISTS该函数返回集合中第一个元素的索引,如果集合为空,返回NULLNULLNULLCollection.EXISTS(index)CO
- 前言本文主要给大家介绍了关于Django快速分页的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。分页在web开发
- 本文实例讲述了Python实现OpenCV的安装与使用。分享给大家供大家参考,具体如下:由于下一步要开始研究下深度学习,而深度学习领域很多的
- if (arr[i]){ &nb
- -- 创建库CREATE TABLE `rate` ( `uname` VARCHAR (300), `object`
- 众所周知,FileSystemObject(fso)组件的强大功能及破坏性是它屡屡被免费主页提供商(那些支持ASP)的禁用的原因,我整理了一
- import socketdef open_tcp_socket(remotehost,servicename): &
- 最近为了熟悉一下 js 用有道翻译练了一下手,写一篇博客记录一下,也希望能对大家有所启迪,不过这些网站更新太快,可能大家尝试的时候会有所不同
- 如下所示:#获取一个值在某个区间的指定倍数的值方法#1# print([i for i in range(1,101) if i%5==0]
- 本文实例讲述了基于scrapy实现的简单蜘蛛采集程序。分享给大家供大家参考。具体如下:# Standard Python library i
- 这次用Python实现的是一个接球打砖块的小游戏,需要导入pygame模块,有以下两条经验总结:1.多父类的继承2.碰撞检测的数学模型知识点
- 本文实例总结了Python2与Python3的区别。分享给大家供大家参考,具体如下:Python的3??.0版本相对于Python的早期版本
- 本文以实例形式讲述了Python实现抓取网页并解析的功能。主要解析问答与百度的首页。分享给大家供大家参考之用。主要功能代码如下:#!/usr
- 一、背景最近在和系统模块做数据联调,其中有一个需求是将两个角色下的相关数据对比后将最新的数据返回出去,于是就想到了去重,再次做一个总结。二、
- 背景介绍最近遇到一个需求,大致就是要获取某个小程序上的数据。心想小程序本质上就是移动端加壳的浏览器,所以想到用Python去获取数据。在网上