Complete the code to add multi-line text to the plot.
import matplotlib.pyplot as plt plt.plot([1, 2, 3]) plt.text(1, 2, 'Line1\n[1]') plt.show()
The '\n' creates a new line in the text. Adding 'Line2' after '\n' shows two lines.
Complete the code to set the font size of multi-line text.
import matplotlib.pyplot as plt plt.plot([1, 2, 3]) plt.text(1, 2, 'Hello\nWorld', fontsize=[1]) plt.show()
The fontsize parameter controls the size of the text. 12 is a common readable size.
Fix the error in the code to correctly display multi-line text with alignment.
import matplotlib.pyplot as plt plt.plot([1, 2, 3]) plt.text(1, 2, 'First line\nSecond line', ha=[1]) plt.show()
The correct horizontal alignment values are 'left', 'center', or 'right'. 'center' centers the text.
Fill both blanks to create multi-line text with vertical and horizontal alignment.
import matplotlib.pyplot as plt plt.plot([1, 2, 3]) plt.text(1, 2, 'Line1\nLine2', ha=[1], va=[2]) plt.show()
Horizontal alignment 'center' centers text horizontally. Vertical alignment 'top' aligns text to the top.
Fill all three blanks to add multi-line text with color, font size, and alignment.
import matplotlib.pyplot as plt plt.plot([1, 2, 3]) plt.text(1, 2, 'Hello\nWorld', color=[1], fontsize=[2], ha=[3]) plt.show()
Color 'green' is chosen, fontsize 14 is readable, and horizontal alignment 'right' aligns text to the right.