0
0
Matplotlibdata~30 mins

Statistical plot enhancements in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Statistical plot enhancements
📖 Scenario: You work as a data analyst for a small company. You have collected sales data for different products over several months. Your manager wants you to create a clear and informative bar chart that shows the sales numbers and highlights the highest sales month.
🎯 Goal: Build a bar chart using matplotlib that shows monthly sales data. You will add enhancements like colors, labels, and a title to make the chart easy to understand and visually appealing.
📋 What You'll Learn
Create a dictionary with monthly sales data
Set a variable for the month with the highest sales
Use a bar chart to plot the sales data
Highlight the highest sales month with a different color
Add labels for the x-axis, y-axis, and a chart title
Display the final plot
💡 Why This Matters
🌍 Real World
Data analysts often need to visualize sales or performance data clearly to help managers make decisions. Highlighting important data points like the highest sales month makes reports more useful.
💼 Career
Knowing how to create and enhance plots with matplotlib is a key skill for data scientists and analysts to communicate insights effectively.
Progress0 / 4 steps
1
Create monthly sales data
Create a dictionary called monthly_sales with these exact entries: 'January': 150, 'February': 200, 'March': 180, 'April': 220, 'May': 170.
Matplotlib
Need a hint?

Use curly braces {} to create a dictionary. Separate each month and sales number with a colon.

2
Identify the highest sales month
Create a variable called highest_month that stores the month with the highest sales from the monthly_sales dictionary.
Matplotlib
Need a hint?

Use the max() function with the key=monthly_sales.get argument to find the month with the highest sales.

3
Create a bar chart with color highlights
Use matplotlib.pyplot to create a bar chart of monthly_sales. Use a list comprehension to create a list of colors where the bar for highest_month is 'orange' and all others are 'blue'. Use this color list in the color parameter of plt.bar().
Matplotlib
Need a hint?

Use a list comprehension to assign colors. Then pass the colors list to the color argument in plt.bar().

4
Add labels and display the plot
Add an x-axis label 'Month', a y-axis label 'Sales', and a title 'Monthly Sales Data' to the plot using plt.xlabel(), plt.ylabel(), and plt.title(). Then display the plot using plt.show().
Matplotlib
Need a hint?

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