0
0
Matplotlibdata~10 mins

Overlaying data on images in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to display an image using matplotlib.

Matplotlib
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

img = mpimg.imread('image.png')
plt.[1](img)
plt.show()
Drag options to blanks, or click blank then click option'
Abar
Bplot
Cscatter
Dimshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.plot instead of plt.imshow
Trying to use plt.scatter for images
2fill in blank
medium

Complete the code to overlay a red circle on the image at coordinates (50, 50).

Matplotlib
import matplotlib.pyplot as plt
import matplotlib.patches as patches

fig, ax = plt.subplots()
ax.imshow(img)
circle = patches.Circle((50, 50), radius=10, color=[1], fill=False)
ax.add_patch(circle)
plt.show()
Drag options to blanks, or click blank then click option'
A'red'
B'yellow'
C'blue'
D'green'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color names without quotes
Choosing a color other than red
3fill in blank
hard

Fix the error in the code to correctly overlay text on the image at position (100, 100).

Matplotlib
fig, ax = plt.subplots()
ax.imshow(img)
ax.text(100, 100, 'Hello', color=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Ared
Bblue
C'red'
D'blue'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color names without quotes causing errors
Using invalid color names
4fill in blank
hard

Fill both blanks to create a scatter plot overlay on the image with blue points at x and y coordinates.

Matplotlib
fig, ax = plt.subplots()
ax.imshow(img)
ax.scatter([1], [2], color='blue')
plt.show()
Drag options to blanks, or click blank then click option'
Ax_coords
By_coords
Cimg
Dpoints
Attempts:
3 left
💡 Hint
Common Mistakes
Using the image variable instead of coordinate lists
Swapping x and y coordinates
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each word to its length if the length is greater than 3.

Matplotlib
word_lengths = { [1]: [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently
Not using len() to get word length