Last active
June 23, 2017 01:41
-
-
Save qfgaohao/8739a01732e5359c2a159bc87a656afe to your computer and use it in GitHub Desktop.
Overlay a rectangle on an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results