Horizontal bar chart with plt.barh
📖 Scenario: You work in a small bakery and want to show how many cakes of each type you sold last week. You want to create a simple horizontal bar chart to share with your team.
🎯 Goal: Create a horizontal bar chart using plt.barh to display the number of cakes sold for each cake type.
📋 What You'll Learn
Create a list called
cake_types with the cake names exactly as: 'Chocolate', 'Vanilla', 'Strawberry', 'Lemon', 'Carrot'Create a list called
cakes_sold with the numbers exactly as: 50, 40, 30, 20, 10Use
plt.barh to create a horizontal bar chart with cake_types on the y-axis and cakes_sold on the x-axisAdd labels for the x-axis as 'Number of Cakes Sold' and y-axis as 'Cake Type'
Display the chart using
plt.show()💡 Why This Matters
🌍 Real World
Horizontal bar charts are useful to compare categories when category names are long or when you want to display data horizontally for better readability.
💼 Career
Data analysts and scientists often use horizontal bar charts to present categorical data clearly in reports and presentations.
Progress0 / 4 steps