The following snippet draws non-overlapping rectangles and works as expected:
JavaScript
x
15
15
1
import matplotlib
2
import matplotlib.pyplot as plt
3
4
fig = plt.figure()
5
ax = fig.add_subplot(111, aspect=1)
6
7
for i in range(5, 30, 5):
8
for j in range(5, 30, 5):
9
rect = matplotlib.patches.Rectangle((i, j), 5, 5, color='blue')
10
ax.add_patch(rect)
11
12
plt.xlim([0, 45])
13
plt.ylim([0, 45])
14
plt.show()
15
But when I wish to make the rectangles transparent, they tend to have a border around them, as shown below:
JavaScript
1
2
1
rect = matplotlib.patches.Rectangle((i, j), 5, 5, color='blue', alpha=0.2)
2
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
JavaScript
1
2
1
rect = matplotlib.patches.Rectangle((i, j), 4.5, 4.5, color='blue', alpha=0.2)
2
I get the following:
A zoomed-in version of the above image is:
As you can see, I still get those boundaries with lower transparency (than alpha=0.2). How can I get rid of those boundaries?
Advertisement
Answer
This will help
JavaScript
1
2
1
rect = matplotlib.patches.Rectangle((i, j), 5, 5, facecolor='blue', alpha=0.2,edgecolor = None)
2