0
0
Matplotlibdata~30 mins

Why patterns solve common tasks in Matplotlib - See It in Action

Choose your learning style9 modes available
Why patterns solve common tasks
📖 Scenario: Imagine you work in a small bakery. You want to understand how many cakes you sell each day of the week to plan better. You have the sales data for a week and want to visualize it.
🎯 Goal: You will create a simple bar chart using matplotlib to show cake sales per day. This project teaches how using a common pattern (looping over data and plotting) helps solve everyday tasks easily.
📋 What You'll Learn
Create a list of days of the week with exact names
Create a list of cake sales numbers matching the days
Use a variable to set the bar color
Use a loop or direct plotting to create a bar chart with labels
Display the chart with correct labels and title
💡 Why This Matters
🌍 Real World
Visualizing sales data helps businesses understand trends and plan better. Using common patterns in code makes this fast and easy.
💼 Career
Data scientists and analysts often create charts to communicate insights. Knowing how to use plotting libraries with patterns is a key skill.
Progress0 / 4 steps
1
Create the sales data lists
Create a list called days with these exact values: 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'. Then create a list called sales with these exact numbers: 20, 35, 30, 35, 27, 40, 50.
Matplotlib
Need a hint?

Use square brackets to create lists. Put the exact day names as strings in days. Put the exact numbers in sales.

2
Set the bar color
Create a variable called bar_color and set it to the string 'skyblue' to use as the color for the bars in the chart.
Matplotlib
Need a hint?

Assign the string 'skyblue' to the variable bar_color.

3
Create the bar chart
Import matplotlib.pyplot as plt. Use plt.bar() with days, sales, and color=bar_color to create the bar chart.
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt at the top. Then call plt.bar() with the correct arguments.

4
Display the chart with labels
Add a title 'Cake Sales by Day' using plt.title(). Label the y-axis as 'Number of Cakes' using plt.ylabel(). Finally, call plt.show() to display the chart.
Matplotlib
Need a hint?

Use plt.title() and plt.ylabel() before plt.show(). The chart window should appear with the correct title.