Incident Category Bar Chart - Python Code Explanation

Goal of the Script

This Python script creates a publication-quality horizontal bar chart showing incident categories among Bangladesh Minority Victims (2025). It calculates the frequency and percentage of incidents in each category and produces high-resolution PNG and PDF chart files.

Code Description

The script uses pandas for reading and processing the incident dataset and matplotlib for creating the visualization.

The input dataset is a CSV file containing incident records with category indicator variables. The program reads the file and calculates category statistics before generating the chart.

Input and Output Files

The script reads:

The script creates:

Incident Categories

The chart displays the following incident categories:

Data Processing Steps

  1. Reads the CSV incident dataset into a pandas DataFrame.
  2. Counts incidents with valid descriptions.
  3. Calculates the number and percentage of incidents for each category.
  4. Creates a summary DataFrame containing category names, counts, and percentages.
  5. Sorts categories for horizontal bar chart display.

Chart Generation

The script creates a horizontal bar chart using matplotlib. Each category is assigned a semantic color, and each bar displays both the incident count and percentage value.

The chart includes:

Important Interpretation Note

Percentages are calculated among incidents with descriptions only. Because one incident may belong to multiple categories, percentages may sum to more than 100 percent.

Summary

This script demonstrates a complete data visualization workflow using Python. It converts categorized incident data into publication-ready charts suitable for reports, dashboards, and research presentations.