Text Annotations with Matplotlib
📖 Scenario: Imagine you are analyzing sales data for a small store. You want to create a simple line chart showing sales over a week and add notes to highlight important days.
🎯 Goal: Build a line chart using matplotlib that shows sales data for 7 days. Add text annotations to highlight the highest and lowest sales days.
📋 What You'll Learn
Create a list called
sales with exact values for 7 daysCreate a list called
days with day names from Monday to SundayAdd a variable called
max_sales to store the highest sales valueAdd a variable called
min_sales to store the lowest sales valueUse
plt.plot() to draw the sales line chartUse
plt.annotate() to add text annotations for highest and lowest salesPrint the plot with
plt.show()💡 Why This Matters
🌍 Real World
Text annotations help highlight key points in charts, making data easier to understand for reports or presentations.
💼 Career
Data analysts and scientists often use annotations to explain trends or outliers in their visualizations.
Progress0 / 4 steps