Lecture

Creating Bar and Pie Charts


Not all data is best shown with lines. If you’re comparing categories or showing proportions, bar charts and pie charts are better options.

This lesson introduces both chart types and when to use them.


Bar Charts

Use plt.bar() to compare values across categories (e.g. sales per product or number of users per region).

Basic Bar Chart
categories = ["A", "B", "C"] values = [10, 25, 15] plt.bar(categories, values) plt.title("Category Comparison") plt.xlabel("Category") plt.ylabel("Value") plt.show()

Bar charts can be vertical (default) or horizontal using plt.barh().


Pie Charts

Use plt.pie() to show parts of a whole — for example, market share percentages or budget distribution.

Basic Pie Chart
labels = ["Rent", "Food", "Transport"] sizes = [40, 35, 25] plt.pie(sizes, labels=labels) plt.title("Monthly Expenses Breakdown") plt.show()

Pie charts are best when you want to highlight relative proportions, not exact quantities.


What’s Next?

Next, you’ll review the overall structure of a Matplotlib plot with a visual slide deck, then test what you’ve learned in a mid-chapter quiz.

Quiz
0 / 1

Which type of chart is best for showing proportions of a whole?

Line Chart

Bar Chart

Pie Chart

Scatter Plot

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help