How To Plot A Circle For Each Point Scatter Plot While Each Has Particular Radius Size
Solution 1:
I'm still not sure which PCA parameter you want to be reflected in the circle size, but: either you want to
- use a scatter plot (i.e.
ax.scatter()
) whosesize=
is reflecting your chosen PCA parameter; this size will (and should not) rescale when you rescale the figure; it is also not given in (x,y)-units - use multiple
plt.Circle((x,y), radius=radius, **kwargs)
patches, whose radii are given in (x,y)-units; the point overlap is then consistent on rescale, but this will likely cause deformed points
The following animation will emphasise the issue at hand:
I suppose you want the plt.Circle
-based solution, as it keeps the distance static, and then you need to "manually" calculate beforehand whether two points overlap and delete them "manually". You should be able to do this automatically via a comparison between point size (i.e. radius
, your PCA parameter) and the euclidian distance between your data points (i.e. np.sqrt(dx**2 + dy**2)
).
To use Circles, you could e.g. define a shorthand function:
def my_circle_scatter(ax, x_array, y_array, radius=0.5, **kwargs):
for x, y in zip(x_array, y_array):
circle = plt.Circle((x,y), radius=radius, **kwargs)
ax.add_patch(circle)
return True
and then call it with optional parameters (i.e. the x- and y-coordinates, colors, and so on):
my_circle_scatter(ax, xs, ys, radius=0.2, alpha=.5, color='b')
Where I've used fig,ax=plt.subplots()
to create the figure and subplot individually.
Post a Comment for "How To Plot A Circle For Each Point Scatter Plot While Each Has Particular Radius Size"