World-country comparisons
Color countries by a metric such as population, rate, or index.
Plotly · Function
Creates an interactive outline choropleth map, coloring geographic polygons according to supplied values. It supports built-in country and US-state geometries as well as custom GeoJSON boundaries.
px.choropleth builds an interactive outline-based map by associating geographic identifiers with numeric values and mapping those values to polygon colors. Identifiers can refer to built-in countries or states, or to features in supplied GeoJSON; the resulting figure uses Plotly's geographic layout.
plotly.express.choropleth(data_frame=None, lat=None, lon=None, locations=None, locationmode=None, geojson=None, featureidkey='id', color=None, hover_name=None, hover_data=None, custom_data=None, animation_frame=None, animation_group=None, category_orders=None, labels=None, color_discrete_sequence=None, color_discrete_map=None, color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, opacity=None, facet_row=None, facet_col=None, facet_col_wrap=None, facet_row_spacing=None, facet_col_spacing=None, facet_col_wrap=None, hover_name=None, hover_data=None, title=None, template=None, width=None, height=None, projection=None, scope=None, center=None, fitbounds=None, basemap_visible=None, **kwargs)| Name | Type | Description |
|---|---|---|
data_frame | DataFrame or array-like | Data frame or array-like data source containing the plotted values and location fields. |
locations | str or array-like | Geographic identifiers or the name of a data-frame column containing them. |
color | str or array-like | Values or the name of a data-frame column used to color regions. |
geojson | dict or str | GeoJSON geometry defining custom geographic features. |
locationmode | str | Interpretation mode for location identifiers, such as ISO-3, USA-states, or country names. |
scope | str | Geographic view to display, such as usa or world. |
color_continuous_scale | str or list | Color scale used for numeric values. |
**kwargs | keyword arguments | Additional Plotly Express and figure-layout options. |
A Plotly graph_objects.Figure containing a choropleth trace and geographic layout.
geojson argument.color argument supplies the quantitative field or sequence used for the color scale.locationmode is set to USA-states.locationmode to match the identifier format; ISO-3 is for three-letter country codes, not arbitrary names.import plotly.express as px
fig = px.choropleth(
locations=["USA", "CAN", "MEX"],
locationmode="ISO-3",
color=[100, 85, 72],
color_continuous_scale="Viridis",
title="Values by country",
)
fig.show()Creates an interactive outline map whose country colors represent the supplied values.
Color countries by a metric such as population, rate, or index.
Display values for states using abbreviations or full state names.
Visualize administrative or statistical boundaries not included by Plotly.
Show how a regional metric changes between time periods.
px.choropleth visualize?px.choropleth creates an outline map made of colored polygons. It combines geographic geometry with values supplied through color, then uses locations to associate each value with a region.
Follow-up: How would you use custom boundaries? Pass GeoJSON through geojson, identify its features with locations, and ensure the feature identifiers align with those locations.
Use locations for region identifiers and locationmode to define how Plotly interprets them. For example, locationmode='ISO-3' makes values such as USA and CAN represent countries.
Follow-up: How would you map US states? Use state identifiers with locationmode='USA-states' and typically set scope='usa' for the geographic view.
Built-in geometries support countries and US states, while custom regions can be supplied as GeoJSON. The color argument provides the numeric values that determine each region's color.
Follow-up: What must be true for custom GeoJSON data to work? Each GeoJSON feature needs an identifier, or an identifying value in its properties, that matches the values used in locations.
px.choropleth_mapgo.Choroplethpx.scatter_geopx.line_geolayout.geo