plot many circles based on x,y,r being vectors in python
Question: x,y are positions of the circles and r is the radius - all vectors.I want to
plot them all at once. Something like:

    
    
    import matplotlib.pyplot as plt
    from matplotlib.patches Circle
    
    #define x,y,r vectors
    
    fig = plt.figure()
    ax1 = fig.add_subplot(1,1,1)
    plt.Circle((x,y),r,color='r')
    plt.show()
    

Thanks.


Answer: I am not informed about the Circles patch, but here is how you can do it with
the standard plot command:

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.array([0.2,0.4])
    y = np.array([0.2,1.2])
    r = np.array([0.5,0.3])
    
    phi = np.linspace(0.0,2*np.pi,100)
    
    na=np.newaxis
    
    # the first axis of these arrays varies the angle, 
    # the second varies the circles
    x_line = x[na,:]+r[na,:]*np.sin(phi[:,na])
    y_line = y[na,:]+r[na,:]*np.cos(phi[:,na])
    
    plt.plot(x_line,y_line,'-')
    plt.show()
    

The basic idea is to give the `plt.plot(...)` command two 2D arrays. In that
case they are interpreted as a list of plots. Espacially for many plots (=many
circles) this is much faster, than plotting circle by circle.

