Bar Graphs with a Crime Data Analysis Project

📊 Data Viz Beginner

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. Simple to create, fun to read, and they make you look smart while analyzing serious data.

Why Use Bar Graphs?

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 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.

More to explore →

Pie Charts · Histogram · Scatter Plots · Line Graphs