ComeçarComece de graça

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.

Este exercício faz parte do curso

Analyzing US Census Data in Python

Ver curso

Instruções do exercício

  • Call the centroid attribute on geo_state_pt and assign the result to the geometry column
  • Create a basemap of state borders by calling the plot method on geo_state; set the color to "tan" and the edgecolor to "black"
  • Create variable ms (to be passed to the markersize parameter) to the square root of the value of the geo_state_pt["internet"] column divided by 5

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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()
Editar e executar o código