Complete the code to set the horizontal alignment of the text to center.
import matplotlib.pyplot as plt plt.text(0.5, 0.5, 'Hello', ha=[1]) plt.show()
The ha parameter controls horizontal alignment. Using 'center' centers the text horizontally.
Complete the code to set the vertical alignment of the text to top.
import matplotlib.pyplot as plt plt.text(0.5, 0.5, 'Top aligned', va=[1]) plt.show()
The va parameter controls vertical alignment. Using 'top' aligns the text to the top.
Fix the error in the code by choosing the correct horizontal alignment value.
import matplotlib.pyplot as plt plt.text(0.5, 0.5, 'Error fix', ha=[1]) plt.show()
The correct horizontal alignment value is 'center'. Other options are invalid and cause errors.
Fill both blanks to center the text horizontally and align it vertically at the baseline.
import matplotlib.pyplot as plt plt.text(0.5, 0.5, 'Aligned Text', ha=[1], va=[2]) plt.show()
Use 'center' for horizontal alignment and 'baseline' for vertical alignment to align text properly.
Fill all three blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.
words = ['data', 'science', 'ai', 'ml'] lengths = { [1] : [2] for [3] in words if len([3]) > 3 }
The dictionary comprehension uses word as the key and len(word) as the value, iterating over word in words.