pyplot rectangle over image

Solutions on MaxInterview for pyplot rectangle over image by the best coders in the world

showing results for - "pyplot rectangle over image"
Josefina
27 Mar 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') # Coordinates: (left, top), width, height
15
16# Add the patch to the Axes
17ax.add_patch(rect)
18
19plt.show()
20