Proportional Symbol Map of Households w/ Internet
To map a raw count variable, you can use a proportional symbol map to create markers of sizes that are proportional to the data value being mapped. In this exercise you will find the centroid of each state, create a basemap of states, and place a circle at each centroid that is sized by the number of households with internet access.
The area of each marker should be proportional to the data value. Since marker sizes are provided as a diameter, you must take the square root of the column value. Marker sizes may look too big or too small. In this exercise, you will divide the marker size by 5--this is an aesthetic judgment call.
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
- Call the
centroidattribute ongeo_state_ptand assign the result to thegeometrycolumn - Create a basemap of state borders by calling the
plotmethod ongeo_state; set thecolorto"tan"and theedgecolorto"black" - Create variable
ms(to be passed to themarkersizeparameter) to the square root of the value of thegeo_state_pt["internet"]column divided by5
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"] = ____
# Set basemap and create variable for markersize
basemap = ____
ms = ____
# Plot proportional symbols on top of basemap
geo_state_pt.plot(ax = basemap, markersize = ms, color = "lightgray", edgecolor = "darkgray")
plt.show()