0% found this document useful (0 votes)
12 views1 page

Chloropleth Population Growth - Py

The document contains a Python script that utilizes libraries such as GeoPandas and Matplotlib to create choropleth maps illustrating population growth in various municipalities over a span of 40 years. It merges population data with geographical data, calculates future populations based on growth rates, and generates and saves maps for each year. The output includes 41 maps, each labeled with the corresponding year from 2020 to 2060.

Uploaded by

Dwyne Marquita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Chloropleth Population Growth - Py

The document contains a Python script that utilizes libraries such as GeoPandas and Matplotlib to create choropleth maps illustrating population growth in various municipalities over a span of 40 years. It merges population data with geographical data, calculates future populations based on growth rates, and generates and saves maps for each year. The output includes 41 maps, each labeled with the corresponding year from 2020 to 2060.

Uploaded by

Dwyne Marquita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1 import geopandas as gpd

2 import pandas as pd
3 import [Link] as plt
4 import os
5 import numpy as np
6
7 # Merge the data as a pandas DataFrame
8 merged_data = [
9 {'Municipality': 'Allen', 'Population (2020)': 25228, 'Annual Growth Rate': -0.002, 'Area': 47.60},
10 {'Municipality': 'Biri', 'Population (2020)': 11274, 'Annual Growth Rate': -0.009, 'Area': 24.62},
11 {'Municipality': 'Bobon', 'Population (2020)': 25964, 'Annual Growth Rate': 0.0197, 'Area': 130.00},
12 {'Municipality': 'Capul', 'Population (2020)': 12323, 'Annual Growth Rate': -0.006, 'Area': 35.56},
13 {'Municipality': 'Catarman', 'Population (2020)': 97879, 'Annual Growth Rate': 0.0085, 'Area': 464.43},
14 {'Municipality': 'Catubig', 'Population (2020)': 32174, 'Annual Growth Rate': -0.0055, 'Area': 217.02},
15 {'Municipality': 'Gamay', 'Population (2020)': 23367, 'Annual Growth Rate': -0.0013, 'Area': 115.10},
16 {'Municipality': 'Laoang', 'Population (2020)': 60607, 'Annual Growth Rate': -0.0026, 'Area': 246.94},
17 {'Municipality': 'Lapinig', 'Population (2020)': 11844, 'Annual Growth Rate': -0.0197, 'Area': 57.30},
18 {'Municipality': 'Las Navas', 'Population (2020)': 36621, 'Annual Growth Rate': -0.0075, 'Area': 282.61},
19 {'Municipality': 'Lavezares', 'Population (2020)': 29390, 'Annual Growth Rate': 0.0045, 'Area': 119.50},
20 {'Municipality': 'Lope de Vega', 'Population (2020)': 14690, 'Annual Growth Rate': 0.0, 'Area': 280.00},
21 {'Municipality': 'Mapanas', 'Population (2020)': 14234, 'Annual Growth Rate': 0.0031, 'Area': 117.85},
22 {'Municipality': 'Mondragon', 'Population (2020)': 41415, 'Annual Growth Rate': 0.0142, 'Area': 288.90},
23 {'Municipality': 'Palapag', 'Population (2020)': 34034, 'Annual Growth Rate': -0.0016, 'Area': 179.60},
24 {'Municipality': 'Pambujan', 'Population (2020)': 35532, 'Annual Growth Rate': 0.0153, 'Area': 163.90},
25 {'Municipality': 'Rosario', 'Population (2020)': 10949, 'Annual Growth Rate': 0.0085, 'Area': 31.60},
26 {'Municipality': 'San Antonio', 'Population (2020)': 8882, 'Annual Growth Rate': -0.0041, 'Area': 27.00},
27 {'Municipality': 'San Isidro', 'Population (2020)': 27867, 'Annual Growth Rate': 0.0094, 'Area': 255.90},
28 {'Municipality': 'San Jose', 'Population (2020)': 17641, 'Annual Growth Rate': 0.001, 'Area': 29.85},
29 {'Municipality': 'San Roque', 'Population (2020)': 29882, 'Annual Growth Rate': -0.0048, 'Area': 152.98},
30 {'Municipality': 'San Vicente', 'Population (2020)': 6928, 'Annual Growth Rate': -0.0261, 'Area': 15.80},
31 {'Municipality': 'Silvino Lobos', 'Population (2020)': 15100, 'Annual Growth Rate': -0.0028, 'Area': 224.20},
32 {'Municipality': 'Victoria', 'Population (2020)': 15361, 'Annual Growth Rate': 0.0076, 'Area': 186.70}
33 ]
34
35 df = [Link](merged_data)
36
37 # Load shapefile
38 gdf = gpd.read_file('C:/Users/DWYNE S MARQUITA/OneDrive/Desktop/Graphing and
Stuff/choropleth/gadm41_PHL_shp/gadm41_PHL_2.shp')
39
40 # Merge the geodataframe with the DataFrame
41 merged_gdf = [Link](df, left_on='NAME_2', right_on='Municipality')
42
43 # Function to calculate new population based on growth rate
44 def calculate_population(population, growth_rate, years):
45 return population * (1 + growth_rate) ** years
46
47 # Create the output directory if it doesn't exist
48 output_dir = 'C:/Users/DWYNE S MARQUITA/OneDrive/Desktop/Graphing and Stuff/choropleth/Population_Growth in 40 years/'
49 [Link](output_dir, exist_ok=True)
50
51 # Plot the choropleth map for each year (from 0 to 40)
52 for year in range(0, 41):
53 # Calculate the population for each year
54 merged_gdf['Calculated Population'] = merged_gdf.apply(
55 lambda row: calculate_population(row['Population (2020)'], row['Annual Growth Rate'], year), axis=1
56 )
57
58 # Plot the choropleth map
59 fig, ax = [Link](1, 1, figsize=(10, 6))
60 ax.set_xlim([124, 125.5])
61 ax.set_ylim([12.2, 12.8])
62
63 # Create a color map that changes with the population
64 merged_gdf.plot(column='Calculated Population', cmap='OrRd', legend=True, ax=ax,
65 legend_kwds={'label': "Population", 'orientation': "horizontal"})
66
67 # Add municipality names as labels without population numbers
68 for x, y, label in zip(
69 merged_gdf.[Link].x,
70 merged_gdf.[Link].y,
71 merged_gdf['Municipality']
72 ):
73 [Link](x, y, label, ha='center', fontsize=8, color='black')
74
75 # Add the year as a title
76 year_label = 2020 + year
77 [Link](f'Population Growth Map for {year_label}', fontsize=14)
78
79 # Save the map for each year
80 output_filename = f'{output_dir}population_choropleth_growth_rate_{year_label}.png'
81 [Link](output_filename)
82
83 # Close the plot after saving
84 [Link]()
85
86 print("41 population growth maps generated with year labels!")
87

You might also like