B. arrowprops should be a dictionary, not a string
C. The text 'High' should be passed as xytext
D. xytext parameter is missing
Solution
Step 1: Check arrowprops usage
arrowprops must be a dictionary specifying arrow style, not a string.
Step 2: Verify other parameters
xytext is present, text is first argument, plot args are correct.
Final Answer:
arrowprops should be a dictionary, not a string -> Option B
Quick Check:
arrowprops = dict(...) not string [OK]
Hint: arrowprops needs dict with arrow style, not string [OK]
Common Mistakes:
Passing arrowprops as string
Confusing text and xytext parameters
Incorrect plot data format
5. You want to highlight the lowest point on a plot with an annotation that includes an arrow and custom text offset. Which code snippet correctly achieves this for data points x=[1,2,3], y=[5,3,6]?
hard
A. plt.annotate('Lowest', xy=(2, 3), xytext=(2, 3), arrowprops=dict(color='blue'))
B. plt.annotate('Lowest', xytext=(2, 3), xy=(1, 4), arrowprops='red')
C. plt.text('Lowest', xy=(2, 3), xytext=(1, 4), arrowprops=dict(facecolor='red'))
D. plt.annotate('Lowest', xy=(2, 3), xytext=(1, 4), arrowprops=dict(facecolor='red'))
Solution
Step 1: Identify the lowest point coordinates
Lowest y is 3 at x=2, so xy=(2,3) is correct.
Step 2: Check annotation parameters
xytext=(1,4) offsets text for clarity, arrowprops uses dict with facecolor for arrow color.
Step 3: Validate options
plt.annotate('Lowest', xy=(2, 3), xytext=(1, 4), arrowprops=dict(facecolor='red')) matches correct syntax and logic. Others misuse parameters or functions.
Final Answer:
plt.annotate('Lowest', xy=(2, 3), xytext=(1, 4), arrowprops=dict(facecolor='red')) -> Option D