add rectangle matplotlib

Solutions on MaxInterview for add rectangle matplotlib by the best coders in the world

showing results for - "add rectangle matplotlib"
Henry
01 Oct 2019
1import matplotlib.pyplot as plt
2import matplotlib.patches as patches
3from PIL import Image
4
5im = Image.open('stinkbug.png')
6
7# Create figure and axes
8fig, ax = plt.subplots()
9
10# Display the image
11ax.imshow(im)
12
13# Create a Rectangle patch
14rect = patches.Rectangle((50, 100), 40, 30, linewidth=1, edgecolor='r', facecolor='none')
15
16# Add the patch to the Axes
17ax.add_patch(rect)
18
19plt.show()
20