Bar Charts
A bar chart is one of the most common and intuitive ways to visualize data - using rectangular bars to represent and compare values across different categories, with the bar length proportional to the value it represents.
When to Use a Bar Chart
Bar charts work best when comparing a categorical variable against a numeric one - for example, comparing sales across different regions, or the number of students enrolled in different courses.
Vertical vs Horizontal Bar Charts
Vertical bar charts (column charts) are the most common, while horizontal bar charts are often preferred when category names are long, or when there are many categories to display, since they're easier to read top to bottom.
Plotting in Python
import matplotlib.pyplot as plt
categories = ["North", "South", "East", "West"]
sales = [250, 180, 300, 210]
plt.bar(categories, sales, color="steelblue")
plt.xlabel("Region")
plt.ylabel("Sales")
plt.title("Sales by Region")
plt.show()
Grouped and Stacked Bar Charts
When comparing multiple sub-categories at once, grouped bar charts place bars side by side, while stacked bar charts stack them on top of each other to also show the total across sub-categories.
Coming Up Next
While bar charts compare categories, understanding how a single numeric variable is distributed calls for a different chart - the Histogram.