Choroplethmap
Overview
The choroplethmap
trace type is used to create choropleth maps on top of a MapLibre layer. It's a more advanced form of the standard choropleth
trace, allowing for greater control over map projections, interactivity, and advanced map features like zooming and tilting.
With choroplethmap
, you can visualize data across geographic regions on MapLibre maps, and customize the map's appearance using layers, color scales, and hover labels.
Common Uses
- Geospatial Data Visualization: Displaying data on an interactive MapLibre map.
- Thematic Mapping with Interactivity: Creating maps that can zoom, tilt, and rotate while visualizing variables like population or economic metrics.
- Map Projections: Applying various MapLibre projections for advanced geographical data representation.
Check out the Attributes for the full set of configuration options
Examples
Common Configurations
Here's a simple choroplethmap
map showing population density across different regions on a MapLibre layer:
You can copy this code below to create this chart in your project:
models:
- name: country-population-data-map
args:
- echo
- |
iso_alpha,population_density
USA,36
CAN,4
RUS,9
CHN,153
IND,450
traces:
- name: Simple ChoroplethMapLibre Map
model: ref(country-population-data-map
props:
type: choroplethmap
geojson: "https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson"
locations: ?{iso_alpha}
z: ?{population_density}
colorscale: "Blues"
marker:
opacity: 0.7
charts:
- name: Simple ChoroplethMapLibre Chart
traces:
- ${ref(Simple ChoroplethMapLibre Map)}
layout:
title:
text: Population Density by Country on MapLibre<br><sub>Data in Persons per Square Kilometer</sub>
mapbox:
style: "carto-positron"
zoom: 1
center:
lat: 20
lon: 0
This example shows a choropleth map on a MapLibre layer using a custom color scale, zoom, and center on Europe:
Here's the code:
models:
- name: european-gdp-data
args:
- echo
- |
iso_alpha,gdp
FRA,2716
DEU,3846
ITA,2001
ESP,1419
GBR,2827
traces:
- name: ChoroplethMapLibre with Custom Colorscale Trace
model: ${ref(european-gdp-data)}
props:
type: choroplethmap
geojson: "https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson"
locations: ?{iso_alpha}
z: ?{gdp}
colorscale: [[0, "rgb(255,245,240)"], [0.5, "rgb(252,146,114)"], [1, "rgb(165,15,21)"]]
marker:
opacity: 0.75
charts:
- name: ChoroplethMapLibre with Custom Colorscale
traces:
- ${ref(ChoroplethMapLibre with Custom Colorscale Trace)}
layout:
title:
text: GDP by Country in Europe<br><sub>Data in Billions of USD</sub>
mapbox:
style: "carto-positron"
zoom: 3
center:
lat: 50
lon: 10
Here's a choropleth map on a MapLibre layer that includes hover information for each country:
You can copy this code below to create this chart in your project:
models:
- name: covid-data-map
args:
- echo
- |
iso_alpha,covid_cases,covid_deaths
USA,33000000,600000
BRA,20000000,550000
IND,30000000,400000
RUS,6000000,150000
ZAF,2000000,60000
traces:
- name: Interactive ChoroplethMapLibre with Hover Data Trace
model: ${ref(covid-data-map)}
props:
type: choroplethmap
geojson: "https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson"
locations: ?{iso_alpha}
z: ?{covid_cases}
colorscale: "Reds"
text: ?{covid_deaths}
hovertemplate: "Cases: %{z}<br>Deaths: %{text}"
marker:
opacity: 0.8
charts:
- name: Interactive ChoroplethMapLibre with Hover Data
traces:
- ${ref(Interactive ChoroplethMapLibre with Hover Data Trace)}
layout:
title:
text: COVID-19 Cases by Country on MapLibre<br><sub>Hover to See Deaths Data</sub>
mapbox:
style: "carto-darkmatter"
zoom: 2
center:
lat: 30
lon: 0
A schema to validate plotly trace properties
Attributes
These attributes apply to traces where trace.props.type
is set to choroplethmap
. You would configure these attributes on the trace with the trace.props
object.
autocolorscale: boolean
below: 'string' #(1)!
coloraxis: string
colorbar:
bgcolor: any
bordercolor: any
borderwidth: number
exponentformat: any
len: number
lenmode: any
minexponent: number
nticks: integer
orientation: any
outlinecolor: any
outlinewidth: number
separatethousands: boolean
showexponent: any
showticklabels: boolean
showtickprefix: any
showticksuffix: any
thickness: number
thicknessmode: any
tickangle: number
tickcolor: any
tickfont:
color: any
family: 'string' #(2)!
lineposition: any
shadow: 'string' #(3)!
size: number
style: any
textcase: any
variant: any
weight: integer
tickformat: 'string' #(4)!
tickformatstops: array
ticklabeloverflow: any
ticklabelposition: any
ticklabelstep: integer
ticklen: number
tickmode: any
tickprefix: 'string' #(5)!
ticks: any
ticksuffix: 'string' #(6)!
ticktext: array
ticktextsrc: 'string' #(7)!
tickvals: array
tickvalssrc: 'string' #(8)!
tickwidth: number
title:
font:
color: any
family: 'string' #(9)!
lineposition: any
shadow: 'string' #(10)!
size: number
style: any
textcase: any
variant: any
weight: integer
side: any
text: 'string' #(11)!
x: number
xanchor: any
xpad: number
xref: any
y: number
yanchor: any
ypad: number
yref: any
colorscale: any
customdata: array
customdatasrc: 'string' #(12)!
featureidkey: 'string' #(13)!
hoverinfo: array
hoverinfosrc: 'string' #(14)!
hoverlabel:
align: array
alignsrc: 'string' #(15)!
bgcolor: array
bgcolorsrc: 'string' #(16)!
bordercolor: array
bordercolorsrc: 'string' #(17)!
font:
color: array
colorsrc: 'string' #(18)!
family: 'string | array' #(19)!
familysrc: 'string' #(20)!
lineposition: array
linepositionsrc: 'string' #(21)!
shadow: 'string | array' #(22)!
shadowsrc: 'string' #(23)!
size: array
sizesrc: 'string' #(24)!
style: array
stylesrc: 'string' #(25)!
textcase: array
textcasesrc: 'string' #(26)!
variant: array
variantsrc: 'string' #(27)!
weight: array
weightsrc: 'string' #(28)!
namelength: array
namelengthsrc: 'string' #(29)!
hovertemplate: 'string | array' #(30)!
hovertemplatesrc: 'string' #(31)!
hovertext: 'string | array' #(32)!
hovertextsrc: 'string' #(33)!
ids: array
idssrc: 'string' #(34)!
legend: string
legendgroup: 'string' #(35)!
legendgrouptitle:
font:
color: any
family: 'string' #(36)!
lineposition: any
shadow: 'string' #(37)!
size: number
style: any
textcase: any
variant: any
weight: integer
text: 'string' #(38)!
legendrank: number
legendwidth: number
locations: array
locationssrc: 'string' #(39)!
marker:
line:
color: array
colorsrc: 'string' #(40)!
width: array
widthsrc: 'string' #(41)!
opacity: array
opacitysrc: 'string' #(42)!
metasrc: 'string' #(43)!
name: 'string' #(44)!
reversescale: boolean
selected:
marker:
opacity: number
showlegend: boolean
showscale: boolean
stream:
maxpoints: number
token: 'string' #(45)!
subplot: string
text: 'string | array' #(46)!
textsrc: 'string' #(47)!
type: choroplethmap
uid: 'string' #(48)!
unselected:
marker:
opacity: number
visible: any
z: array
zauto: boolean
zmax: number
zmid: number
zmin: number
zsrc: 'string' #(49)!
- Determines if the choropleth polygons will be inserted before the layer with the specified ID. By default, choroplethmap traces are placed above the water layers. If set to '', the layer will be inserted above every existing layer.
- HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
- Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
- Sets the tick label formatting rule using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46
- Sets a tick label prefix.
- Sets a tick label suffix.
- Sets the source reference on Chart Studio Cloud for
ticktext
. - Sets the source reference on Chart Studio Cloud for
tickvals
. - HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
- Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
- Sets the title of the color bar.
- Sets the source reference on Chart Studio Cloud for
customdata
. - Sets the key in GeoJSON features which is used as id to match the items included in the
locations
array. Support nested property, for example properties.name. - Sets the source reference on Chart Studio Cloud for
hoverinfo
. - Sets the source reference on Chart Studio Cloud for
align
. - Sets the source reference on Chart Studio Cloud for
bgcolor
. - Sets the source reference on Chart Studio Cloud for
bordercolor
. - Sets the source reference on Chart Studio Cloud for
color
. - HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
- Sets the source reference on Chart Studio Cloud for
family
. - Sets the source reference on Chart Studio Cloud for
lineposition
. - Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
- Sets the source reference on Chart Studio Cloud for
shadow
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
style
. - Sets the source reference on Chart Studio Cloud for
textcase
. - Sets the source reference on Chart Studio Cloud for
variant
. - Sets the source reference on Chart Studio Cloud for
weight
. - Sets the source reference on Chart Studio Cloud for
namelength
. - Template string used for rendering the information that appear on hover box. Note that this will override
hoverinfo
. Variables are inserted using %{variable}, for example "y: %{y}" as well as %{xother}, {%xother}, {%_xother}, {%xother_}. When showing info for several points, xother will be added to those with different x positions from the first point. An underscore before or after (x|y)other will add a space on that side, only when this field is shown. Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. The variables available inhovertemplate
are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data. Additionally, every attributes that can be specified per-point (the ones that arearrayOk: true
) are available. Finally, the template string has access to variableproperties
Anything contained in tag<extra>
is displayed in the secondary box, for example "{fullData.name} ". To hide the secondary box completely, use an empty tag<extra></extra>
. - Sets the source reference on Chart Studio Cloud for
hovertemplate
. - Same as
text
. - Sets the source reference on Chart Studio Cloud for
hovertext
. - Sets the source reference on Chart Studio Cloud for
ids
. - Sets the legend group for this trace. Traces and shapes part of the same legend group hide/show at the same time when toggling legend items.
- HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
- Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
- Sets the title of the legend group.
- Sets the source reference on Chart Studio Cloud for
locations
. - Sets the source reference on Chart Studio Cloud for
color
. - Sets the source reference on Chart Studio Cloud for
width
. - Sets the source reference on Chart Studio Cloud for
opacity
. - Sets the source reference on Chart Studio Cloud for
meta
. - Sets the trace name. The trace name appears as the legend item and on hover.
- The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
- Sets the text elements associated with each location.
- Sets the source reference on Chart Studio Cloud for
text
. - Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
- Sets the source reference on Chart Studio Cloud for
z
.