Adding Legends, Annotations, and Text
You'll learn how to make your plots tell a clearer story by adding informative labels, legends, and visual callouts that guide the viewer's attention.
When you create a visualization, you're not just showing data—you're guiding interpretation. Think of legends, annotations, and text as road signs on a data highway: they help viewers navigate the plot, understand what they're looking at, and discover the insights you want to highlight.
Why This Matters
A plot without context is like a map without street names. Your audience shouldn't have to guess what each line represents or which spike in the data is significant. By adding clear legends, targeted annotations, and descriptive text, you transform raw visuals into actionable insights.
The Three Tools
Legends identify what different visual elements represent—especially crucial when you have multiple lines, colors, or groups. You've already used plt.legend() to display these automatically.
Annotations draw attention to specific data points or regions. Use arrows and text boxes to say "Look here!" when highlighting outliers, thresholds, or turning points. In Matplotlib, plt.annotate() lets you place text with optional arrows pointing to coordinates.
Text labels add context anywhere on your plot. plt.text() places strings at specific (x, y) coordinates, useful for labeling regions, adding disclaimers, or emphasizing values directly on the chart.
Practical Application
Imagine a time series showing sales data with a sudden drop. A simple line chart shows the pattern, but an annotation with an arrow pointing to that date saying "Supply chain disruption" immediately provides context. A legend clarifies which line represents which product category. Strategic text placement reduces cognitive load and makes your visualization self-explanatory.
Key Takeaway: Legends clarify identities, annotations highlight insights, and text provides context—together they transform charts from data displays into compelling stories that guide viewers toward understanding.