0
0
Matplotlibdata~20 mins

Why annotations tell the data story in Matplotlib - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Annotation Storyteller
Get all challenges correct to earn this badge!
Test your skills under time pressure!
visualization
intermediate
2:00remaining
Identify the effect of annotations on a line plot

Look at the line plot with and without annotations. Which statement best describes how annotations help tell the data story?

Matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

plt.figure(figsize=(6,4))
plt.plot(x, y, marker='o')
plt.title('Prime Numbers Line Plot')
plt.xlabel('Index')
plt.ylabel('Prime Number')
# Annotation added
plt.annotate('Highest value', xy=(5, 11), xytext=(3, 10), arrowprops=dict(facecolor='black', shrink=0.05))
plt.show()
AAnnotations add random text that does not relate to the data.
BAnnotations remove data points, simplifying the plot but losing information.
CAnnotations change the data values to make the plot look better.
DAnnotations highlight key points, making it easier to understand important data values.
Attempts:
2 left
💡 Hint

Think about why someone would add text and arrows to a plot.

Predict Output
intermediate
2:00remaining
Output of annotated scatter plot code

What will be the output of this code snippet?

Matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [10, 20, 25, 30]

plt.scatter(x, y)
plt.annotate('Peak', xy=(4, 30), xytext=(3, 28), arrowprops=dict(facecolor='red'))
plt.show()
AA scatter plot with points and an arrow pointing to the point (4, 30) labeled 'Peak'.
BA scatter plot with points but no annotations visible.
CA line plot connecting points with an annotation at (4, 30).
DA scatter plot with an annotation but the arrow points to the wrong location.
Attempts:
2 left
💡 Hint

Check how plt.annotate uses xy and xytext to place the arrow and text.

🔧 Debug
advanced
2:00remaining
Find the error in annotation code

Why does this code raise an error?

Matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3]
y = [5, 7, 9]

plt.plot(x, y)
plt.annotate('Max', xy=(3, 9), xytext=(4, 10), arrowprops=dict(facecolor='blue'))
plt.show()
ASyntaxError due to missing closing parenthesis in plt.annotate line.
BValueError because xytext coordinates are outside the plot range.
CTypeError because arrowprops is not a valid argument.
DNameError because plt is not imported.
Attempts:
2 left
💡 Hint

Check the parentheses carefully in the annotate line.

data_output
advanced
2:00remaining
Count of annotations in a plot

Given this code, how many annotations will appear on the plot?

Matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [4, 3, 2, 1]

plt.plot(x, y)
for i, val in enumerate(y):
    if val < 3:
        plt.annotate(f'Low {val}', xy=(x[i], val), xytext=(x[i], val+0.5), arrowprops=dict(facecolor='green'))
plt.show()
A4 annotations will appear, one for each point.
BNo annotations will appear because the condition is never true.
C2 annotations will appear, for points where y is less than 3.
D3 annotations will appear, but one will overlap and not be visible.
Attempts:
2 left
💡 Hint

Look at the condition val < 3 and count how many y values satisfy it.

🧠 Conceptual
expert
2:00remaining
Why use annotations in data storytelling?

Which of the following best explains why annotations are important in telling a data story?

AAnnotations replace the need for titles and axis labels in plots.
BAnnotations provide context and highlight key insights that might be missed in raw data visuals.
CAnnotations automatically clean and preprocess data for better visualization.
DAnnotations increase the size of the plot to fit more data points.
Attempts:
2 left
💡 Hint

Think about how annotations help a viewer understand the story behind the numbers.