0
0
Matplotlibdata~30 mins

Highlight and annotate pattern in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Highlight and Annotate Pattern
📖 Scenario: You are analyzing sales data for a small store. You want to see the sales trend over a week and highlight the day with the highest sales. This will help you understand when the store performs best.
🎯 Goal: Create a line chart of daily sales. Highlight the day with the highest sales using a different color and add an annotation to show the exact sales value on that day.
📋 What You'll Learn
Create a list called days with the days of the week.
Create a list called sales with the sales numbers for each day.
Find the day with the highest sales and store its index in max_index.
Plot the sales data as a line chart using matplotlib.
Highlight the highest sales day with a red dot.
Add an annotation showing the sales value on the highest sales day.
💡 Why This Matters
🌍 Real World
Highlighting important points in data charts helps businesses quickly see key information like best sales days.
💼 Career
Data analysts and scientists often highlight and annotate charts to communicate insights clearly to teams and managers.
Progress0 / 4 steps
1
Create sales data
Create a list called days with these exact values: 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'. Create another list called sales with these exact values: 150, 200, 170, 220, 180, 300, 250.
Matplotlib
Need a hint?

Use square brackets to create lists. Put the days as strings in days and numbers in sales.

2
Find the highest sales day index
Create a variable called max_index and set it to the index of the highest value in the sales list using the sales.index() method and the max() function.
Matplotlib
Need a hint?

Use max(sales) to get the highest sales number, then find its position with sales.index().

3
Plot sales and highlight highest day
Import matplotlib.pyplot as plt. Plot the sales data as a line chart using plt.plot(days, sales). Highlight the highest sales day by plotting a red dot at days[max_index] and sales[max_index] using plt.scatter() with color 'red' and size 100. Add an annotation with plt.annotate() showing the sales value at the highest sales day. Use the text f'Highest: {sales[max_index]}', position the text slightly above the red dot with xytext=(0,10) and textcoords='offset points'.
Matplotlib
Need a hint?

Use plt.plot() for the line, plt.scatter() for the red dot, and plt.annotate() to add text above the dot.

4
Show the plot
Add plt.show() to display the plot with the highlighted highest sales day and annotation.
Matplotlib
Need a hint?

Use plt.show() to display the chart window.