Bar Graphs with a Crime Data Analysis Project

📊 Data Viz Beginner

Looking at crime data in a spreadsheet can get boring pretty quickly. A bar graph makes it much easier to compare countries and spot which ones have higher or lower crime rates. Instead of drowning in a sea of boring numbers, you get clean visuals that actually make sense. Simple to create, fun to read, and they make you look smart while analyzing serious data.

Why Use Bar Graphs?

Imagine scrolling through hundreds of numbers trying to find the biggest value. A bar graph does that work for you by turning those numbers into something visual. Whether it's crime stats, fav snacks, or top songs — bar graphs make boring numbers look clean and easy to digest.

What You'll Learn

Step-by-Step Code Examples

Plotting a single year (2023)

Python
import matplotlib.pyplot as plt
import numpy as np

countries = [
    "United States", "Brazil", "India", "Germany", "South Africa", "Australia",
    "Canada", "Russia", "Japan", "United Kingdom", "France", "Mexico"
]

crime_2023 = [6800, 7200, 4900, 3500, 7500, 4200, 3900, 5500, 2800, 4700, 4600, 6900]

plt.figure(figsize=(10, 5))
plt.bar(countries, crime_2023, label="2023", zorder=3, width=0.5, color="#376dc5")

plt.xticks(rotation=40, ha='right')
plt.title("Crime Rates Across Countries in 2023")
plt.xlabel("Countries")
plt.ylabel("Number of Crimes")
plt.grid(True, linestyle='--', alpha=0.5, zorder=0)
plt.legend()

plt.tight_layout()
plt.show()

Output:

Single year bar chart output

Plotting 2023 & 2024 side by side

Python
import matplotlib.pyplot as plt
import numpy as np

countries = [
    "United States", "Brazil", "India", "Germany", "South Africa", "Australia",
    "Canada", "Russia", "Japan", "United Kingdom", "France", "Mexico"
]

crime_2023 = [6800, 7200, 4900, 3500, 7500, 4200, 3900, 5500, 2800, 4700, 4600, 6900]
crime_2024 = [6500, 7000, 4700, 3300, 7100, 4000, 3800, 5300, 2600, 4500, 4300, 6600]

plt.figure(figsize=(10, 6))

x = np.arange(len(countries))
width = 0.3

plt.bar(x - width / 2, crime_2023, width=width, label="2023", color="#262F58", zorder=3)
plt.bar(x + width / 2, crime_2024, width=width, label="2024", color="#247FC9", zorder=3)

plt.xticks(x, countries, rotation=45, ha='right')
plt.title('Crime Comparison (2023 vs 2024)')
plt.xlabel("Countries")
plt.ylabel("Number of Crimes")
plt.grid(True, linestyle='--', alpha=0.6, zorder=0)
plt.legend(loc="upper right")

plt.tight_layout()
plt.show()

Output:

Side-by-side bar chart output

Mini Project: Visualize Top Crime Cities

Let's build a real-world horizontal bar chart using an actual crime dataset — Indian cities with the highest number of reported crimes.

📥 Download the dataset (CSV) — crime_city_insights.csv

How to Use This Dataset

Not familiar with Pandas? No worries — here's a quick guide to get started.

Python
import pandas as pd

crime = pd.read_csv("crime_city_insights.csv")

That's it! Use the crime variable to explore the dataset. Try crime.head() to view the top rows or crime.describe() for basic stats.

Frequently Asked Questions

What is a bar graph in Python?

A bar graph is a chart that uses rectangular bars to compare values across categories. In Python, bar graphs are commonly created using Matplotlib's plt.bar() function.

When should I use a bar graph?

Use a bar graph when you want to compare quantities between different groups, such as countries, products, students, or cities.

What is the difference between a bar graph and a histogram?

A bar graph compares categories, while a histogram shows the distribution of numerical data.

More to explore →

Pie Charts · Histogram · Scatter Plots · Line Graphs