Map of the US

“If there’s a place you gotta go I’m the one you need to know. I’m the map.”

1. As usual:

import pandas as pd
import geopandas
import math
import matplotlib.pyplot as plt

2. Make sure to download all the files in the states_2020 folder

states = geopandas.read_file('states_2020/cb_2020_us_state_5m.shp')
states.head()

3. PolygonPatch

from descartes.patch import PolygonPatch

4. Make a mini plot

states.plot(); 

5. Get rid of excess states

states_50 = states[~states['STUSPS'].isin(['GU', 'AS', 'AK', 'PR', 'VI', 'MP'])]
states_50.head()
states_50.plot();

6. Boundary plot

states_50.boundary.plot(figsize=(40,15))

7. Labeled US map

fig, ax = plt.subplots(figsize=(29,12))
states_50.apply(lambda x: ax.annotate(s=x.STUSPS, xy=x.geometry.centroid.coords[0], ha='center', fontsize=11, color = 'black'), axis=1);
states_50.boundary.plot(ax=ax, color='black', linewidth = .2)
states_50.plot(ax=ax, cmap = 'Blues')
plt.savefig('US_state_map')
fig, ax = plt.subplots(figsize=(29,12))
states_50.apply(lambda x: ax.annotate(s=x.STUSPS, xy=x.geometry.centroid.coords[0], ha='center', fontsize=11, color = 'white'), axis=1);
states_50.boundary.plot(ax=ax, color='black', linewidth = .2)
states_50.plot(ax=ax, cmap = 'flag')

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store