1

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:

        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?

1 Answer 1

1

This will help

rect = matplotlib.patches.Rectangle((i, j), 5, 5, facecolor='blue', alpha=0.2,edgecolor = None)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.