您当前的位置: 首页 >  Python

星拱北辰

暂无认证

  • 0浏览

    0关注

    1205博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Python】Matplotlib使用字符串代替变量绘制散点图

星拱北辰 发布时间:2020-02-15 21:59:50 ,浏览量:0

要点说明

在绘制散点图的时候,通常使用变量作为输入数据的载体。 其实,也可以使用字符串作为输入数据的存储载体。

下面代码的data = {“a”: x, “b”: y, “color”: c, “size”: s}正是将散点图的输入数据、颜色和标记大小放在数据字典data中作为键值对,对应的key是字符串string。

Matplotlib编程实现
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca()

x = np.random.rand(50)*10
y = np.random.rand(50)*10+20
s = np.random.rand(50)*100
c = np.random.rand(50)

data = {"a": x, "b": y, "color": c, "size": s}

ax.scatter("a", "b", c="color", s="size", data=data)

ax.set(xlabel="X", ylabel="Y")

plt.show()
成品图

在这里插入图片描述

关注
打赏
1660750074
查看更多评论
立即登录/注册

微信扫码登录

0.4359s