Bivariate Map of Broadband Access
Sometimes we want to map two variables at once, a so-called bivariate map. One way to do this is by combining a choropleth map and a proportional symbol map. You will use the geo_state
GeoDataFrame again to create a choropleth of the percentage of internet households with broadband access, and overaly a proportional symbol map of the count of households with internet access.
You will set an alpha
transparency on the proportional symbol marker so as to not completely obscure the underlying choropleth.
geopandas
is imported using the usual alias, and the sqrt
function has been imported from numpy
.
The geo_state
GeoDataFrame has been loaded.
This exercise is part of the course
Analyzing US Census Data in Python
Exercise instructions
- Use the
broadband
andinternet
columns to calculate the percentage of internet households with broadband - Create a choropleth basemap of the new
pct_broadband
column using a yellow-green-blue colormap - Set the
markersize
of the centroid points to the square root of the number of households withinternet
access divided by5
; make the markers partially transparent by setting thealpha
parameter to0.7
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create point GeoDataFrame at centroid of states
geo_state_pt = geo_state.copy()
geo_state_pt["geometry"] = geo_state_pt.centroid
# Calculate percentage of internet households with broadband
geo_state["pct_broadband"] = ____
# Set choropleth basemap
basemap = ____
# Plot transparent proportional symbols on top of basemap
geo_state_pt.plot(ax = basemap, ____, color = "lightgray", edgecolor = "darkgray", ____)
plt.show()