0
0
Matplotlibdata~10 mins

Multi-line text 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 multi-line text to the plot.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.text(1, 2, 'Line1\n[1]')
plt.show()
Drag options to blanks, or click blank then click option'
ALine3
BLine5
CLine4
DLine2
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use '\n' for new lines
Using a single line string without '\n'
2fill in blank
medium

Complete the code to set the font size of multi-line text.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.text(1, 2, 'Hello\nWorld', fontsize=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A12
B5
C20
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of integer for fontsize
Choosing too small or too large font sizes
3fill in blank
hard

Fix the error in the code to correctly display multi-line text with alignment.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.text(1, 2, 'First line\nSecond line', ha=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'middle'
B'center'
C'centre'
D'left'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect alignment strings like 'middle' or 'centre'
Omitting quotes around the alignment string
4fill in blank
hard

Fill both blanks to create multi-line text with vertical and horizontal alignment.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.text(1, 2, 'Line1\nLine2', ha=[1], va=[2])
plt.show()
Drag options to blanks, or click blank then click option'
A'center'
B'top'
C'bottom'
D'left'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up ha and va parameters
Using invalid alignment strings
5fill in blank
hard

Fill all three blanks to add multi-line text with color, font size, and alignment.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.text(1, 2, 'Hello\nWorld', color=[1], fontsize=[2], ha=[3])
plt.show()
Drag options to blanks, or click blank then click option'
A'blue'
B14
C'right'
D'green'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers as strings for fontsize
Using invalid color names
Wrong alignment strings