I need to produce a choropleth county level map for the entire country of America. My issue right now is that I cannot adjust Alaska and Hawaii to get them in the bottom left corner of my map, below California and to the left of Texas. My program so far is below but it is not producing any changes in the size and or position of Alaska and Hawaii.
import geopandas as gpd
import matplotlib.pyplot as plt
# Load the shapefile
shape_path = '/Users/deas/Documents/Research/cb_2018_us_county_20m/cb_2018_us_county_20m.shp'
shape = gpd.read_file(shape_path)
# Territories to exclude
to_exclude = ['03', '07', '14', '43', '52', '72']
# Define a list of ALL state FIPS codes
state_fips_codes = shape['STATEFP'].unique()
# Exclude specified codes from the list
state_fips_codes = [code for code in state_fips_codes if code not in to_exclude]
# Filter the shapefile to include only the desired states
shape = shape[shape['STATEFP'].isin(state_fips_codes)]
shape = shape.sort_values('STATEFP')
# Create a map with Alaska and Hawaii scaled and repositioned
fig, ax = plt.subplots(figsize=(12, 6))
# Plot the shapefile (continental US)
shape.boundary.plot(ax=ax, edgecolor='black', linewidth=0.4)
# Scale and reposition Alaska
alaska = shape[shape['STATEFP'] == '02']
alaska['geometry'] = alaska['geometry'].scale(xfact=0.4, yfact=0.4) # Adjust the scaling factor
alaska['geometry'] = alaska['geometry'].translate(xoff=-50, yoff=-70) # Adjust the translation
# Scale and reposition Hawaii
hawaii = shape[shape['STATEFP'] == '15']
hawaii['geometry'] = hawaii['geometry'].scale(xfact=0.5, yfact=0.5) # Adjust the scaling factor
hawaii['geometry'] = hawaii['geometry'].translate(xoff=-20, yoff=-100) # Adjust the translation
# Plot the modified Alaska and Hawaii
alaska.boundary.plot(ax=ax, edgecolor='black', linewidth=0.4)
hawaii.boundary.plot(ax=ax, edgecolor='black', linewidth=0.4)
# Set the extent of the map to cover the entire US
ax.set_xlim(-175, -60)
ax.set_ylim(18, 72)
# Turn off axis labels and ticks
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
ax.axis('off')
ax.set_aspect('equal')
plt.title('Title', size=18, weight='bold')
plt.show()
I am using a shapefile from the Census Bureau, the columns are given as follows:
Index(['STATEFP', 'COUNTYFP', 'COUNTYNS', 'AFFGEOID', 'GEOID', 'NAME', 'LSAD',
'ALAND', 'AWATER', 'geometry'],
dtype='object')
And lastly I need to write this program in Python, I have seen some answers for R but none for Python. Any help here would be massively appreciated!