Creating a graduated color visualization

This code will manually assign colors to specific sections of the data, breaking the data into categories. This also assigns specific radius sizes to data so that the visualization will convey information with both color and circle size:

color_stops = [
[0.0, 'rgb(107,174,214)'], [3000.0, 'rgb(116,196,118)'],
[8000.0, 'rgb(254,153,41)'],
[max(tract_points['Total Population']), 'rgb(222,45,38)'],
]

minmax = [min(tract_points['Percent Male']),
max(tract_points['Percent Male'])]
diff = minmax[1] - minmax[0]
radius_stops = [
[round(minmax[0],2), 4.0],
[round(minmax[0]+(diff/6.0),2), 7.0],
[round(minmax[1]-(diff/2.0),2), 10.0],
[minmax[1], 15.0],]

With these radius sizes and color ranges set, they can be applied to two fields within the new GeoJSON: Total Population and Percent Male. For this visualization, the size of the circle will indicate the male percentage of the population, and the color will indicate the total population:

vizGrad = GraduatedCircleViz('tract_points2.geojson', access_token=token)

vizGrad.color_function_type = 'interpolate'
vizGrad.color_stops = color_stops
vizGrad.color_property = 'Total Population'
vizGrad.color_default = 'grey'
vizGrad.opacity = 0.75

vizGrad.radius_property = 'Percent Male'
vizGrad.radius_stops = radius_stops
vizGrad.radius_function_type = 'interpolate'
vizGrad.radius_default = 1

vizGrad.center = (-122, 37.75)
vizGrad.zoom = 9
vizGrad.show()

This will produce an interactive map like this:

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

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