0
0
Matplotlibdata~10 mins

Tick marks and tick labels 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 set the x-axis tick labels to ['A', 'B', 'C'].

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.xticks([1, 2, 3], [1])
plt.show()
Drag options to blanks, or click blank then click option'
A['A', 'B', 'C']
B[1, 2, 3]
C['X', 'Y', 'Z']
D['4', '5', '6']
Attempts:
3 left
💡 Hint
Common Mistakes
Using the tick positions list instead of labels.
Not matching the number of labels to tick positions.
2fill in blank
medium

Complete the code to set the y-axis ticks at positions 0, 5, and 10.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([0, 1, 2], [0, 5, 10])
plt.yticks([1])
plt.show()
Drag options to blanks, or click blank then click option'
A[1, 2, 3]
B[0, 5, 10]
C['0', '5', '10']
D[0, 1, 2]
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of numbers for tick positions.
Setting ticks outside the data range.
3fill in blank
hard

Fix the error in the code to correctly set x-axis tick labels to ['Low', 'Medium', 'High'].

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [10, 20, 30])
plt.xticks([1, 2, 3], [1])
plt.show()
Drag options to blanks, or click blank then click option'
A['10', '20', '30']
B['low', 'medium', 'high']
C[1, 2, 3]
D['Low', 'Medium', 'High']
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers instead of strings for labels.
Mismatching the number of labels and tick positions.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 letters.

Matplotlib
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B==
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Using the word itself instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 3 letters.

Matplotlib
words = ['apple', 'bat', 'carrot', 'dog']
result = [1]: [2] for w in words if len(w) [3] 3}
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C>
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word instead of uppercase.
Using the wrong comparison operator.