Complete the code to add an annotation at point (2, 4) with text 'Point A'.
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 4, 5]) plt.annotate('Point A', xy=(2, 4), xytext=[1]) plt.show()
xytext as xy causing overlap.The xytext parameter sets the position of the annotation text. (3, 5) places the text slightly above and to the right of the point (2, 4).
Complete the code to annotate the point (3, 5) with an arrow pointing to it.
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()
arrowprops.arrowstyle causing no arrow to appear.The arrowprops dictionary defines the style of the arrow. {'arrowstyle': '->'} draws a simple arrow pointing from the text to the point.
Fix the error in the code to correctly annotate the point (1, 3) with text 'Start'.
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 4, 5]) plt.annotate('Start', xy=[1], xytext=(0, 4)) plt.show()
xy.The xy parameter requires a tuple of coordinates. Using (1, 3) is correct. Lists or strings cause errors.
Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
words = ['data', 'science', 'is', 'fun'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension maps each word to its length using len(word). The condition len(word) > 3 filters words longer than 3 characters.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 2.
words = ['AI', 'ML', 'Data', 'Code'] result = {{ [1]: [2] for w in words if [3] }}
The comprehension maps the uppercase version of each word (w.upper()) to its length (len(w)) only if the length is greater than 2 (len(w) > 2).