0
0
Matplotlibdata~10 mins

Annotating specific points 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 add an annotation at point (2, 4) with text 'Point A'.

Matplotlib
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [3, 4, 5])
plt.annotate('Point A', xy=(2, 4), xytext=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A(2, 5)
B(3, 5)
C(1, 3)
D(2, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same coordinates for xytext as xy causing overlap.
Forgetting to import matplotlib.pyplot as plt.
2fill in blank
medium

Complete the code to annotate the point (3, 5) with an arrow pointing to it.

Matplotlib
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [3, 4, 5])
plt.annotate('Max', xy=(3, 5), xytext=(4, 6), arrowprops=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A{'linestyle': '--'}
B{'color': 'red'}
C{'linewidth': 2}
D{'arrowstyle': '->'}
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a dictionary to arrowprops.
Not specifying arrowstyle causing no arrow to appear.
3fill in blank
hard

Fix the error in the code to correctly annotate the point (1, 3) with text 'Start'.

Matplotlib
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [3, 4, 5])
plt.annotate('Start', xy=[1], xytext=(0, 4))
plt.show()
Drag options to blanks, or click blank then click option'
A(1, 3)
B[1, 3]
C'(1, 3)'
D(3, 1)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a tuple for xy.
Passing coordinates as a string.
4fill in blank
hard

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

Matplotlib
words = ['data', 'science', 'is', 'fun']
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Checking if the word is greater than 3 instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 2.

Matplotlib
words = ['AI', 'ML', 'Data', 'Code']
result = {{ [1]: [2] for w in words if [3] }}
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
Clen(w) > 2
Dw.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word instead of uppercase.
Not filtering words by length correctly.