如何在散点图上设置圆形标记的固定/静态大小?

Phy*_*ist 3 geometry scatter matplotlib marker

我想在散点图上绘制一些随机生成的磁盘的位置,并查看磁盘是否相互"连接".为此,我需要设置固定/链接到轴刻度的每个磁盘的半径.函数中
's'参数plt.scatter使用点,因此大小不是相对于轴固定的.如果我动态缩放到绘图中,散点图标的大小在绘图上保持不变,并且不会随轴向上缩放.
如何设置半径以使它们具有一定值(相对于轴)?

Sch*_*sch 5

而不是使用plt.scatter,我建议使用patches.Circle绘制图(类似于这个答案).这些修补程序的大小保持固定,因此您可以动态放大以检查"连接":

import matplotlib.pyplot as plt
from matplotlib.patches import Circle # for simplified usage, import this patch

# set up some x,y coordinates and radii
x = [1.0, 2.0, 4.0]
y = [1.0, 2.0, 2.0]
r = [1/(2.0**0.5), 1/(2.0**0.5), 0.25]

fig = plt.figure()

# initialize axis, important: set the aspect ratio to equal
ax = fig.add_subplot(111, aspect='equal')

# define axis limits for all patches to show
ax.axis([min(x)-1., max(x)+1., min(y)-1., max(y)+1.])

# loop through all triplets of x-,y-coordinates and radius and
# plot a circle for each:
for x, y, r in zip(x, y, r):
    ax.add_artist(Circle(xy=(x, y), 
                  radius=r))

plt.show()
Run Code Online (Sandbox Code Playgroud)

这个生成的图看起来像这样:

初始情节

使用绘图窗口中的缩放选项,可以获得这样的图:

放大

此放大版本保留了原始圆圈大小,因此可以看到"连接".


如果要将圆圈更改为透明,请patches.Circle使用alphaas参数.只要确保你插入它而Circle不是add_artist:

ax.add_artist(Circle(xy=(x, y), 
              radius=r,
              alpha=0.5))
Run Code Online (Sandbox Code Playgroud)