0
0
Matplotlibdata~30 mins

Lollipop charts in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Create a Lollipop Chart with Matplotlib
📖 Scenario: You work in a small bakery and want to show how many lollipops were sold each day last week. You want to create a simple chart to share with your team.
🎯 Goal: Build a lollipop chart using matplotlib to display the number of lollipops sold each day of the week.
📋 What You'll Learn
Create a dictionary with days of the week as keys and lollipop sales as values.
Create a list of days from the dictionary keys.
Create a list of sales from the dictionary values.
Use matplotlib to plot a lollipop chart with vertical lines and dots.
Label the x-axis with days and y-axis with sales.
Display the chart.
💡 Why This Matters
🌍 Real World
Lollipop charts are simple and clear ways to show comparisons between categories, like daily sales or survey results.
💼 Career
Data analysts and scientists use lollipop charts to present data trends clearly to teams and stakeholders.
Progress0 / 4 steps
1
DATA SETUP: Create the sales data dictionary
Create a dictionary called sales with these exact entries: 'Monday': 10, 'Tuesday': 15, 'Wednesday': 7, 'Thursday': 12, 'Friday': 20, 'Saturday': 25, 'Sunday': 18.
Matplotlib
Need a hint?

Use curly braces {} to create a dictionary. Put days as keys and sales numbers as values.

2
CONFIGURATION: Extract days and sales lists
Create a list called days from the keys of sales. Create a list called values from the values of sales.
Matplotlib
Need a hint?

Use list() with sales.keys() and sales.values() to get the lists.

3
CORE LOGIC: Plot the lollipop chart
Import matplotlib.pyplot as plt. Use plt.stem() with days and values to create the lollipop chart. Set the marker format to 'o' and line format to '-' for dots and lines.
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt to import. Then call plt.stem() with the correct arguments.

4
OUTPUT: Label and show the chart
Use plt.xlabel() to label the x-axis as 'Days'. Use plt.ylabel() to label the y-axis as 'Lollipops Sold'. Use plt.title() to add the title 'Lollipop Sales Last Week'. Finally, use plt.show() to display the chart.
Matplotlib
Need a hint?

Use plt.xlabel(), plt.ylabel(), and plt.title() to add labels and title. Then call plt.show() to display the chart.