matplotlib:绘制散点图

以1月份和9月份的最高气温为例,绘制散点图。

import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
y_1 = [12, 12, 9, 13, 12, 12, 10, 10, 9, 11, 14, 10, 11, 9, 13, 14, 15, 14, 12, 10, 10, 10, 11, 12, 8, 7, 8, 7, 12, 7, 11]
y_9 = [27, 24, 22, 27, 32, 34, 28, 21, 26, 28, 30, 30, 27, 20, 21, 24, 24, 26, 24, 24, 26, 24, 17, 22, 25, 22, 22, 28, 26, 28]

x_1 = range(1, 32)
x_9 = range(32, 62)

plt.figure(figsize=(16, 4))

plt.scatter(x_1, y_1, label='1月份')
plt.scatter(x_9, y_9, label='9月份')

x_ticks = list(x_1) + list(x_9)
x_ticks_labels = [f'1月{i}号' for i in x_1] + [f'9月{i - 31}号' for i in x_9]
plt.xticks(x_ticks[::4], x_ticks_labels[::4], rotation=45)
plt.title('最高气温随时间的变化')

plt.legend()

plt.show()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值