1

i would like to move a rectangle around in my image. I found out how to get an rectangle in my image with the code below. But now I would like to know if I can also get a rotated position of my rectangle for like 30 degrees.

import matplotlib.pyplot as plt
import matplotlib.patches as patches
from PIL import Image

im = Image.open(r'path...\aero1.jpg')

# Create figure and axes
fig, ax = plt.subplots()

# Display the image
ax.imshow(im)

# Create a Rectangle patch
rect = patches.Rectangle((200, 200), 40, 30, linewidth=1, edgecolor='r', facecolor='none')

# Add the patch to the Axes
ax.add_patch(rect)

plt.show()

enter image description here

1 Answers1

1

Use angle argument:

patches.Rectangle((200, 200), 40, 30, linewidth=1, edgecolor='r', facecolor='none', angle=30)

Output:

enter image description here

Alderven
  • 7,569
  • 5
  • 26
  • 38