Creating a choropleth map

With a choropleth map, we can display a polygon GeoJSON file. Using the tracts GeoDataFrame, we'll create another GeoDataFrame with polygon geometry and one tabular field, and save it to a file as GeoJSON:

tract_poly = tracts
tract_poly['Male Population'] = tract_poly['ACS_15_5YR_S0101_with_ann_Male; Estimate; Total population']
tract_poly = tract_poly[['Male Population','geometry' ]]
tract_poly.to_file('tracts_bayarea2.geojson', driver="GeoJSON")

The visualization is created using the ChoroplethViz class. The basemap style is the URL of the satellite imagery style created earlier in the MapBox Studio, section of the chapter:

vizClor = ChoroplethViz('tracts_bayarea2.geojson', 
access_token=API_TOKEN,
color_property='Male Population',
color_stops=create_color_stops([0, 2000, 3000,5000,7000, 15000],
colors='YlOrRd'),
color_function_type='interpolate',
line_stroke='-',
line_color='rgb(128,0,38)',
line_width=1,
opacity=0.6,
center=(-122, 37.75),
zoom=9)
vizClor.style='mapbox://styles/lokipresident/cjftywpln22sp9fcpqa8rl'
vizClor.show()

The output generated is as follows:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset