0
0
Matplotlibdata~15 mins

Vertical bar chart with plt.bar in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Vertical Bar Chart with plt.bar
📖 Scenario: You work in a small bakery. You want to show how many cakes you sold each day last week. A simple bar chart will help you see which days were busiest.
🎯 Goal: Create a vertical bar chart using plt.bar to display the number of cakes sold each day of the week.
📋 What You'll Learn
Create a list called days with the days: 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'.
Create a list called cakes_sold with the exact numbers: 20, 35, 30, 35, 27, 40, 45.
Use plt.bar to make a vertical bar chart with days on the x-axis and cakes_sold on the y-axis.
Add labels for the x-axis as 'Days' and y-axis as 'Number of Cakes Sold'.
Add a title 'Cakes Sold Last Week'.
Display the chart with plt.show().
💡 Why This Matters
🌍 Real World
Bar charts are a simple way to show comparisons, like sales over days or months, helping businesses see trends quickly.
💼 Career
Data analysts and scientists often use bar charts to present data clearly to teams and decision makers.
Progress0 / 4 steps
1
Create the data lists
Create a list called days with these exact values: 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'. Then create a list called cakes_sold with these exact numbers: 20, 35, 30, 35, 27, 40, 45.
Matplotlib
Need a hint?

Use square brackets to create lists. Separate items with commas.

2
Import matplotlib and set up the plot
Import matplotlib.pyplot as plt. This will let you create the bar chart.
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt to import the plotting library.

3
Create the vertical bar chart
Use plt.bar with days as the x values and cakes_sold as the heights of the bars. Then add x-axis label 'Days', y-axis label 'Number of Cakes Sold', and the title 'Cakes Sold Last Week'.
Matplotlib
Need a hint?

Use plt.bar(x, y) to create bars. Use plt.xlabel(), plt.ylabel(), and plt.title() to add labels and title.

4
Display the bar chart
Use plt.show() to display the bar chart you created.
Matplotlib
Need a hint?

Use plt.show() to see the chart window pop up.