Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Circles in matplotlib overlapping when they should not

I am trying to plot two circles in python using matplotlib. I chose their positions such that they should not overlap. However, in the plot it looks like they do. Can anyone tell me where my mistake is?

overlapping circles

    import numpy as np
    import matplotlib.pyplot as plt
    plt.rcParams['figure.dpi'] = 5000

    radius = 0.0025
    positions = np.array([[0.5, 0.05], [0.5 + 2*radius + 0.001, 0.05]])

    fig, ax = plt.subplots()
    ax.cla() 
    ax.set_xlim((0, 1.0))
    ax.set_ylim((0, 0.1))
    ax.set_aspect('equal')
    for n in range(len(positions)):
        circle = plt.Circle((positions[n, 0], positions[n, 1]), radius=radius,                              color='r')
        ax.add_patch(circle)
    plt.show()
    fig.savefig("circles.png")

many thanks in advance!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The reason is the Circle patch is drawn as a face and an edge – the edge has a thickness, which is what is overlapping.

We can resolve this by setting the facecolor to red, and the edgecolor to None, so it doesn’t get plotted.

For example:

circle = plt.Circle((positions[n, 0], positions[n, 1]), radius=radius,
                    facecolor='r', edgecolor='None')

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading