Mapbox - Choropleth Maps¶
Thematic maps with color-coded polygons and legend.
In [ ]:
Copied!
# %pip install anymap-ts
# %pip install anymap-ts
Load US States and Create Choropleth¶
US states GeoJSON with population density, styled with YlOrRd colormap.
In [ ]:
Copied!
from anymap_ts import MapboxMap
m = MapboxMap(center=[-98, 39], zoom=4)
us_states_url = "https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json"
m.add_choropleth(
us_states_url,
column="density",
cmap="YlOrRd",
legend=True,
legend_title="Population Density",
)
m
from anymap_ts import MapboxMap
m = MapboxMap(center=[-98, 39], zoom=4)
us_states_url = "https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json"
m.add_choropleth(
us_states_url,
column="density",
cmap="YlOrRd",
legend=True,
legend_title="Population Density",
)
m
Legend Integration¶
The choropleth automatically adds a legend when legend=True. Customize with legend_title.
In [ ]:
Copied!
# Legend is already added above. You can add a standalone legend for other layers:
# m.add_legend(title="Custom", labels=["A", "B"], colors=[[255,0,0], [0,255,0]])
# Legend is already added above. You can add a standalone legend for other layers:
# m.add_legend(title="Custom", labels=["A", "B"], colors=[[255,0,0], [0,255,0]])