matplotlib绘图【散点图】

import random

from matplotlib import pyplot as plt
from matplotlib import font_manager


# def gen_random_num(num):
#     random_list = []
#     for i in range(num):
#         random_list.append(random.randint(20, 36))
#     return random_list

my_font = font_manager.FontProperties(fname="/usr/share/fonts/opentype/noto/NotoSerifCJK-Bold.ttc",
                                      size="x-small")

# y轴坐标
y_3 = [4, 11, 10, 13, 8, 15, 7, 12, 9, 10, 6, 10, 10, 15, 9, 3, 9, 10, 7, 7, 8, 15, 14, 4, 4, 14, 7, 5, 13, 12, 8]
y_10 = [30, 26, 26, 27, 24, 23, 34, 29, 22, 21, 25, 35, 30, 21, 36, 20, 35, 21, 22, 29, 24, 23, 28, 21, 22, 26, 23, 32, 32, 31, 22]

# x轴坐标
x_3 = range(1, 32)
x_10 = range(51, 82)


# 设置图形大小
plt.figure(figsize=(20, 8), dpi=80)

# 绘制散点图, label配合legend图例一起使用
plt.scatter(x_3, y_3, label="3月份")
plt.scatter(x_10, y_10, label="10月份")

# 调整x轴的刻度(字符串拼接)
_x = list(x_3) + list(x_10)
_xtick_labels = ['3月{}日'.format(i) for i in x_3]
_xtick_labels += ['10月{}日'.format(i-50) for i in x_10]
plt.xticks(_x, _xtick_labels, fontproperties=my_font, rotation=45)

# 添加图例
plt.legend(loc="upper left", prop=my_font)

# 添加描述信息
plt.xlabel("时间", fontproperties=my_font)
plt.ylabel("温度", fontproperties=my_font)
plt.title("标题", fontproperties=my_font)

# 展示
plt.show()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值