Simulate area of action of points in matplotlib

0

I need to create a graph where, given the coordinates of the points, a circle of x-ray is created around these points. Simulating the area of operation.

I have the following script:

================================
import matplotlib.pyplot as plt    

    x = [10, 15, 24, 34]
    y = [10, 42, 27, 14]
    x0 = 10
    y0 = 10
    r0 = 2
    plt.plot(x, y, '.')
    circle = plt.Circle((x0, y0), r0, color='r', fill=False)
    plt.gca().add_artist(circle)
    plt.axis([0, 50, 0, 50])
    plt.show()
================================

That generates the following image:

But I can not make all the points have their circles around.

How can I do this?

    
asked by anonymous 08.03.2018 / 23:15

1 answer

2

Instead of building the circle on a point directly:

x0 = 10
y0 = 10

circle = plt.Circle((x0, y0), r0, color='r', fill=False)
plt.gca().add_artist(circle)

You should do this for all of them by going through the list of x and y you have. To simplify this you can use the zip function that allows you to merge / merge two iterables, which in your case will give x,y to each point.

Soon you would just need to change the code I mentioned above by:

for xi,yi in zip(x,y):
    circle = plt.Circle((xi, yi), r0, color='r', fill=False)
    plt.gca().add_artist(circle)

See the result:

Complete code for reference:

import matplotlib.pyplot as plt

x = [10, 15, 24, 34]
y = [10, 42, 27, 14]
r0 = 2
plt.plot(x, y, '.')

for xi,yi in zip(x,y):
    circle = plt.Circle((xi, yi), r0, color='r', fill=False)
    plt.gca().add_artist(circle)

plt.axis([0, 50, 0, 50])
plt.show()
    
08.03.2018 / 23:58