Contents
Bar Charts and Column Charts
Bar charts are one of the easiest and most useful charts for comparing categories. They are understood by almost everyone. This topic shows how to create several types and how to make them clean and readable.
a. Vertical and Horizontal Bar Charts
A vertical bar chart, also called a column chart, places categories along the bottom and values on the side. Use bar() to create it.
products = ["A", "B", "C", "D"]
units = [50, 80, 65, 40]
fig, ax = plt.subplots()
ax.bar(products, units)
plt.show()A horizontal bar chart places categories on the side. Use barh() for it. This layout works better when category names are long, since the labels have room to read easily.
Both versions show the same information. Choose the one that fits your labels and the space you have.
b. Grouped Bar Charts
A grouped bar chart places bars for several series side by side within each category. It is useful for comparing, for example, sales in two different years for every product.
To build one in Matplotlib, you shift the bar positions slightly using NumPy.
import numpy as np
x = np.arange(len(products))
width = 0.35
ax.bar(x - width/2, sales_2025, width, label="2025")
ax.bar(x + width/2, sales_2026, width, label="2026")
ax.set_xticks(x)
ax.set_xticklabels(products)
ax.legend()Keep the number of groups small. More than three or four series in each group makes the chart crowded and hard to read.
c. Stacked Bar Charts
A stacked bar chart places the parts on top of each other so that each bar shows a total and its pieces. It helps you see both the overall size and the contribution of each part.
ax.bar(products, online, label="Online")
ax.bar(products, store, bottom=online, label="Store")
ax.legend()The bottom setting tells Matplotlib where to start the second bar. Stacked bars are good for showing totals, but only the bottom part is easy to compare across bars.
If comparing the parts is the main goal, a grouped bar chart is often a better choice.
d. Sorting and Labeling Bars
Sorting makes a bar chart much easier to read. Arrange bars from the largest to the smallest, unless the categories have a natural order, such as months or age groups.
df_sorted = df.sort_values("units", ascending=False)
ax.bar(df_sorted["product"], df_sorted["units"])
Adding value labels on top of the bars helps readers get exact numbers without guessing. Use ax.bar_label() for this.
bars = ax.bar(df_sorted["product"], df_sorted["units"])
ax.bar_label(bars)Always start the value axis at zero for bar charts. Cutting the axis makes small differences look huge and can mislead your audience.
Data Visualization Tutorial
Wesline Rinisha








