matplotlib_02_散点图

#假设通过爬虫你获取到了某市2016年3,10月份每天白天的最高气温(分别位于列表a,b),那么此时如何寻找出气温和随时间(天)变化的某种规律?
from matplotlib import pyplot as plt

plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False

y_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]
y_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]

x_a = range(1,len(a)+1)
# 平移
x_b = range(len(a)+11,len(a)+42)
# 画板
plt.figure(figsize = (20,12),dpi = 100)

# 绘图(如果横坐标都是x,散点相互覆盖)
plt.scatter(x_a,y_a,c = 'm',label ="三月")
plt.scatter(x_b,y_b,color = 'y',label = "十月")

# 调整刻度
x = list(x_a)+list(x_b)
xlabel = ["3月{}日".format(i) for i in x_a]
# x_b里面包含的是42-72范围内的int星数据,所以i可以和41做减法
xlabel += ["10月{}日".format(i-41) for i in x_b]

plt.xticks(x[::3],xlabel[::3])

# 添加描述信息
plt.xlabel("月份")
plt.ylabel("气温,摄氏度")
plt.title("某市三月、十月最高气温")

#图例
plt.legend(loc = 2)

plt.savefig("scatter.png")
# 展示
plt.show()

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值