python用小矩形标记数据点_Python – 在散点处绘制已知大小的矩形

虽然@拉尔夫-HTP的答案是非常干净,并使用散射,据我所知道的标记的规模,以点数表示(见例如

here).此外,如果放大,自定义标记不会改变大小.

也许这就是你要找的东西.如果没有,使用单独的Rectangle对象也很有效.这允许您指定的宽度和高度的数据单元,而不是点,你可以放大如有必要,很容易应用旋转,以及,通过设置角度属性:

from matplotlib import pyplot as plt

from matplotlib.patches import Rectangle

# Your data

a = ([126, 237, 116, 15, 136, 348, 227, 247, 106, 5, -96, 25, 146],

[117, 127, 228, 107, 6, 137, 238, 16, 339, 218, 97, -4, -105])

# Your scatter plot

fig = plt.figure()

ax = fig.add_subplot(111)

ax.scatter(a[0], a[1], color = 'red', s=10)

# Add rectangles

width = 30

height = 20

a_zipped = zip(*a)

for a_x, a_y in a_zipped:

ax.add_patch(Rectangle(xy=(a_x-width/2, a_y-height/2) ,width=width, height=height, linewidth=1, color='blue', fill=False))

ax.axis('equal')

plt.show()

结果:

注意:如果需要,您可以通过ax.get_children获得了Rectangle实例().

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值