# -*- coding: utf-8 -*- """ Created on Wed Jul 22 02:26:13 2026 @author: muhuri """ #=========================================================== # Program: # pgm3_BDM_Incident_Category_BarCharts.py # # Purpose: # Create publication-quality horizontal bar chart # showing incident categories. #=========================================================== import pandas as pd import matplotlib.pyplot as plt #----------------------------------------------------------- # Input and output files #----------------------------------------------------------- input_file = ( r"C:\Explore\BDMDataTables\CSVText" r"\BD_Minority_Victims_2025_incident.csv" ) output_png = ( r"C:\Explore\BDMDataTables\Charts" r"\Incident_Categories_BarChart.png" ) output_pdf = ( r"C:\Explore\BDMDataTables\Charts" r"\Incident_Categories_BarChart.pdf" ) #----------------------------------------------------------- # Read CSV file #----------------------------------------------------------- df = pd.read_csv(input_file) #----------------------------------------------------------- # Number of incidents with descriptions #----------------------------------------------------------- n_incidents = ( df["incident_category"] != "Missing Description" ).sum() #----------------------------------------------------------- # Categories to display #----------------------------------------------------------- category_labels = { "violence_against_persons": "Violence Against Persons", "attacks_on_religious_sites": "Attacks on Religious Sites", "property_damage": "Property Damage", "land_grabbing": "Land Grabbing", "killings": "Killings", "missing_abducted": "Missing-Abducted", "blasphemy_related_attacks": "Blasphemy-Related Attacks", "rape": "Rape" } #----------------------------------------------------------- # Semantic colors #----------------------------------------------------------- category_colors = { "Violence Against Persons": "#CD5C5C", # Indian Red "Attacks on Religious Sites": "#B22222", # Crimson "Property Damage": "#D2691E", "Land Grabbing": "#8B4513", "Killings": "#8B0000", "Missing-Abducted": "#4682B4", "Blasphemy-Related Attacks": "#2F4F4F", "Rape": "#800080" } #----------------------------------------------------------- # Calculate counts and percentages #----------------------------------------------------------- results = [] for variable, label in category_labels.items(): count = int(df[variable].sum()) percent = 100 * count / n_incidents results.append([label, count, percent]) results = pd.DataFrame( results, columns=["Category", "Count", "Percent"] ) results = results.sort_values( by="Percent", ascending=True ) #----------------------------------------------------------- # Create chart #----------------------------------------------------------- plt.figure(figsize=(11, 6.5)) bar_colors = [ category_colors[c] for c in results["Category"] ] bars = plt.barh( results["Category"], results["Percent"], color=bar_colors, edgecolor="black", linewidth=0.8 ) #----------------------------------------------------------- # Add count and percentage labels #----------------------------------------------------------- for bar, count, pct in zip( bars, results["Count"], results["Percent"] ): plt.text( bar.get_width() + 0.6, bar.get_y() + bar.get_height()/2, f"{count} ({pct:.1f}%)", va="center", fontsize=11, fontweight="bold" ) #----------------------------------------------------------- # Titles #----------------------------------------------------------- plt.title( "Incident Categories Among Bangladesh Minority Victims (2025)", fontsize=18, fontweight="bold", pad=18 ) plt.xlabel( "Percent of Incidents", fontsize=13 ) #----------------------------------------------------------- # Grid #----------------------------------------------------------- plt.grid( axis="x", linestyle="--", alpha=0.35 ) #----------------------------------------------------------- # Footnote #----------------------------------------------------------- plt.figtext( 0.01, 0.01, "Percentages are based on incidents with descriptions only (n = " f"{n_incidents:,}).\n" "Incidents may belong to multiple categories; therefore percentages " "sum to more than 100%.\n" "Data Owner and Source: Bangladesh Hindu Buddhist Christian Unity Council (BHBCUC)", ha="left", fontsize=10 ) #----------------------------------------------------------- # Axis limits #----------------------------------------------------------- plt.xlim( 0, results["Percent"].max() + 12 ) plt.tight_layout(rect=[0, 0.06, 1, 1]) #----------------------------------------------------------- # Save charts #----------------------------------------------------------- plt.savefig( output_png, dpi=300, bbox_inches="tight" ) plt.savefig( output_pdf, bbox_inches="tight" ) plt.show() #----------------------------------------------------------- # Console output #----------------------------------------------------------- print("\nCharts written to:") print(output_png) print(output_pdf)