-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate_Charts_Project_7.py
More file actions
85 lines (68 loc) · 3.11 KB
/
Copy pathCreate_Charts_Project_7.py
File metadata and controls
85 lines (68 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
# --------------------------------------------------
# PROJECT 7: Kenya Health Service Accessibility Analysis
# Script: Create charts from county-level health access analysis
# Author: Vivian Mbachi
# --------------------------------------------------
# Set project folders
project_folder = Path(r"C:\Users\HP\Downloads\Kenya_Health_Service_Accessibility_Analysis")
output_folder = project_folder / "06_Output"
charts_folder = project_folder / "09_Charts"
# Input file
summary_file = output_folder / "HealthAccess_Analysis_CountySummary_Kenya_2020_2019.csv"
# Load data
df = pd.read_csv(summary_file)
# --------------------------------------------------
# Chart 1: Top 10 counties with highest population per facility
# --------------------------------------------------
top10_pressure = df.sort_values("population_per_facility", ascending=False).head(10)
plt.figure(figsize=(12, 7))
plt.bar(top10_pressure["county"], top10_pressure["population_per_facility"])
plt.title("Top 10 Counties with Highest Population per Health Facility")
plt.xlabel("County")
plt.ylabel("Population per Health Facility")
plt.xticks(rotation=45, ha="right")
plt.tight_layout()
plt.savefig(charts_folder / "Chart_Top10_Highest_Population_Per_Facility_Kenya_2020_2019.png", dpi=300)
plt.close()
# --------------------------------------------------
# Chart 2: Top 10 counties with highest number of health facilities
# --------------------------------------------------
top10_facilities = df.sort_values("total_facilities", ascending=False).head(10)
plt.figure(figsize=(12, 7))
plt.bar(top10_facilities["county"], top10_facilities["total_facilities"])
plt.title("Top 10 Counties by Number of Health Facilities")
plt.xlabel("County")
plt.ylabel("Number of Health Facilities")
plt.xticks(rotation=45, ha="right")
plt.tight_layout()
plt.savefig(charts_folder / "Chart_Top10_Total_Health_Facilities_Kenya_2020.png", dpi=300)
plt.close()
# --------------------------------------------------
# Chart 3: Top 10 counties with highest number of hospital beds
# --------------------------------------------------
top10_beds = df.sort_values("total_beds", ascending=False).head(10)
plt.figure(figsize=(12, 7))
plt.bar(top10_beds["county"], top10_beds["total_beds"])
plt.title("Top 10 Counties by Total Hospital Beds")
plt.xlabel("County")
plt.ylabel("Total Hospital Beds")
plt.xticks(rotation=45, ha="right")
plt.tight_layout()
plt.savefig(charts_folder / "Chart_Top10_Total_Hospital_Beds_Kenya_2020.png", dpi=300)
plt.close()
# --------------------------------------------------
# Chart 4: Histogram of population per facility
# --------------------------------------------------
plt.figure(figsize=(10, 6))
plt.hist(df["population_per_facility"], bins=10)
plt.title("Distribution of Population per Health Facility Across Counties")
plt.xlabel("Population per Health Facility")
plt.ylabel("Number of Counties")
plt.tight_layout()
plt.savefig(charts_folder / "Chart_Distribution_Population_Per_Facility_Kenya_2020_2019.png", dpi=300)
plt.close()
print("Charts created successfully.")
print("Saved charts in:", charts_folder)