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

How to remove boundaries in matplotlib rectangles?

The following snippet draws non-overlapping rectangles and works as expected:

import matplotlib
import matplotlib.pyplot as plt
    
fig = plt.figure()
ax = fig.add_subplot(111, aspect=1)
    
for i in range(5, 30, 5):
    for j in range(5, 30, 5):
        rect = matplotlib.patches.Rectangle((i, j), 5, 5, color='blue')
        ax.add_patch(rect)

plt.xlim([0, 45])
plt.ylim([0, 45])
plt.show()

enter image description here

But when I wish to make the rectangles transparent, they tend to have a border around them, as shown below:

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

        rect = matplotlib.patches.Rectangle((i, j), 5, 5, color='blue', alpha=0.2)

enter image description here

Initially, I thought maybe that was due to some overlaps. So, I reduced the size of the rectangles, but I still got it.
For example, if I use

        rect = matplotlib.patches.Rectangle((i, j), 4.5, 4.5, color='blue', alpha=0.2)

I get the following:

enter image description here

A zoomed-in version of the above image is:

enter image description here

As you can see, I still get those boundaries with lower transparency (than alpha=0.2). How can I get rid of those boundaries?

>Solution :

This will help

rect = matplotlib.patches.Rectangle((i, j), 5, 5, facecolor='blue', alpha=0.2,edgecolor = None)
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