Lecture

Creating Bar and Pie Charts

Not all datasets are best visualized with lines.

When you need to compare categories or show proportions, bar charts and pie charts are often more effective.

In this lesson, you’ll learn how to create both using Matplotlib.


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 visualize parts of a whole, such as market shares, budget allocations, or time spent on activities.

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 work best for showing relative proportions rather than precise numerical comparisons.

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