matplotlib散点图

散点图:

绘制方法和折线图一样,不同之处在于绘图方法使用的是plt.scatter()
在同一张图中绘制多个数据的散点图时,只需要让每个数据对应不同的下标就行了。

实例如下:

import random
from matplotlib import pyplot as plt
import matplotlib

font = {‘family’: ‘STKAITI’,
‘weight’: ‘bold’,
‘size’: 12}
matplotlib.rc(“font”, **font)

#得到x、y轴坐标
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]

print(len(y_3), len(y_10))

x_3 = list(range(1, 32))
x_10 = list(range(41, 72))

##绘制刻度对应的文字
x_id = x_3[::3]+x_10[::3]
x_label_3 = [“3月{}日”.format(i) for i in x_3]
x_label_10 = [“10月{}日”.format(i) for i in x_3]
x_label = x_label_3[::3] + x_label_10[::3]
plt.xticks(x_id, x_label, rotation=45)

y_label = list(range(min(*y_3, *y_10), max(*y_3, *y_10)+1))
plt.yticks(y_label)

#图像描述信息
plt.xlabel(“日期”)
plt.ylabel(“温度 (单位 ℃)”)
plt.title(“气温变化”)

#绘图
plt.scatter(x_3, y_3, label=“3月”, color=“orange”, linewidths=1)
plt.scatter(x_10, y_10, label=“10月”, color=“blue”, linewidths=1)
plt.legend()

#加网格线
plt.grid()

plt.show()

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值