Skip to content

Instantly share code, notes, and snippets.

@qfgaohao
Last active June 23, 2017 01:41
Show Gist options
  • Save qfgaohao/8739a01732e5359c2a159bc87a656afe to your computer and use it in GitHub Desktop.
Save qfgaohao/8739a01732e5359c2a159bc87a656afe to your computer and use it in GitHub Desktop.
Overlay a rectangle on an image
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from skimage import data
# get image
img = data.astronaut()
print('image size', img.shape)
fig, ax = plt.subplots()
ax.imshow(img)
# define patch
patch_loc = (150, 15)
width = 150
height = 170
patch = mpatches.Rectangle(patch_loc, width, height, fill=False, color='blue')
# show
ax.add_patch(patch)
plt.tight_layout()
plt.show()
@qfgaohao
Copy link
Author

Results

u

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment