Learn Bar Graphs with a Crime Data Analysis Project in Python

Bar graphs are super handy for comparing stuff — like which country has more crime and who’s leading the chaos chart. Instead of drowning in a sea of boring numbers, you get clean visuals that actually make sense. They're simple to create, fun to read, and lowkey make you look smart while analyzing serious stuff. So yeah, bar graphs? Totally underrated.

Why Use Bar Graphs?

Bar graphs aren't just for school projects — they’re your go-to tool when you wanna flex data in a clean and loud way. They help you spot trends, compare stuff at a glance, and tell a story without saying a word. Whether it's crime stats, fav snacks, or top songs — bar graphs make boring numbers look cool and easy to digest. If clarity had a visual BFF, it's definitely a bar graph.

What You’ll Learn

Step-by-Step Code Example

Here’s a simple example of how to create a bar graph in Matplotlib:

🔹 For plotting only one data at a time (e.g., 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")

# Lighter grid behind bars
plt.grid(True, linestyle='--', alpha=0.5, zorder=0)
plt.legend()

plt.tight_layout()
plt.show()

        

And here’s what we got :










🔹 For plotting 2023 & 2024 side by side (dual plots):

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()

        

And here’s what we got :










🔹Mini Project: Visualize Top Crime Cities

Let’s build a real-world horizontal bar chart using an actual crime dataset! This project shows the Indian cities with the highest number of reported crimes.

Click here to download the dataset (CSV)

How to Use This Dataset (Beginner Friendly Guide)

Not familiar with Pandas? Don’t worry! Here’s a quick guide to get you started

Python
Copied!

import pandas as pd

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

That’s it! You can now use the variable crime to explore the dataset using Pandas. Try things like crime.head() to view the top rows or crime.describe() for basic stats.

More educational content :