0
0
Matplotlibdata~30 mins

Annotating specific points in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Annotating Specific Points on a Plot
📖 Scenario: You are analyzing sales data over a week. You want to highlight the highest and lowest sales days on a line chart to make the report clearer.
🎯 Goal: Create a line plot of daily sales and annotate the highest and lowest sales points with labels.
📋 What You'll Learn
Create a dictionary with daily sales data
Create variables to find the highest and lowest sales values
Use matplotlib to plot the sales data
Annotate the highest and lowest sales points on the plot
Display the plot
💡 Why This Matters
🌍 Real World
Annotating specific points on charts helps highlight important data in reports and presentations, making it easier for others to understand key insights.
💼 Career
Data analysts and scientists often need to create clear visualizations with annotations to communicate findings effectively to stakeholders.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called daily_sales with these exact entries: 'Monday': 150, 'Tuesday': 200, 'Wednesday': 170, 'Thursday': 220, 'Friday': 180, 'Saturday': 90, 'Sunday': 130.
Matplotlib
Need a hint?

Use curly braces to create a dictionary with the given day names as keys and sales numbers as values.

2
Find highest and lowest sales values
Create two variables: max_sales to store the highest sales value and min_sales to store the lowest sales value from the daily_sales dictionary.
Matplotlib
Need a hint?

Use the max() and min() functions on the dictionary values.

3
Plot sales data and annotate points
Import matplotlib.pyplot as plt. Create a line plot of the sales data using plt.plot() with days on the x-axis and sales on the y-axis. Then, annotate the highest sales point with the label 'Highest' and the lowest sales point with the label 'Lowest' using plt.annotate(). Use the exact variables max_sales and min_sales to find the points to annotate.
Matplotlib
Need a hint?

Use plt.plot() with markers to show points. Use list comprehensions to find the days for max and min sales. Use plt.annotate() with xy and xytext to label points.

4
Display the plot
Use plt.show() to display the plot with the annotated highest and lowest sales points.
Matplotlib
Need a hint?

Call plt.show() to open the plot window and see your graph with annotations.