Skip to content

Choropleth

Overview

The choropleth trace type is used to create choropleth maps, which represent data through color intensity across different geographic regions. This trace is commonly used to display data such as population density, election results, or any data that can be associated with geographic regions.

The choropleth trace allows you to control the region coloring based on a variable, and you can customize the map's appearance using color scales, hover labels, and other styling options.

Common Uses

  • Geographic Data Visualization: Showing data distributions across countries, states, or other regions.
  • Density Mapping: Displaying population or other density metrics across regions.
  • Thematic Mapping: Creating maps that represent different data points based on a color gradient (e.g., GDP, COVID-19 cases).

Examples

Common Configurations

Here's a simple choropleth map showing population density across different countries:

You can copy this code below to create this chart in your project:

models:
  - name: country-population-data
    args:
      - echo
      - |
        country,population_density
        USA,38 
        BRA,25
        ARG,17
        UK,286
        CAN,4
        RUS,9
        CHN,153
        IND,450
        COD,48
traces:
  - name: Simple Choropleth Map Trace
    model: ${ref(country-population-data)}
    props:
      type: choropleth
      locations: ?{country}
      z: ?{population_density}
      colorscale: "Picnic"
charts:
  - name: Simple Choropleth Map
    traces:
      - ${ref(Simple Choropleth Map Trace)}
    layout:
      title:
        text: Population Density by Country<br><sub>Data in Persons per Square Kilometer</sub>
      geo:
        showcoastlines: true
        projection:
          type: "natural earth"

A schema to validate plotly trace properties

Attributes

These attributes apply to traces where trace.props.type is set to choropleth. You would configure these attributes on the trace with the trace.props object.

autocolorscale: boolean
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' #(1)!
    lineposition: any
    shadow: 'string' #(2)!
    size: number
    style: any
    textcase: any
    variant: any
    weight: integer
  tickformat: 'string' #(3)!
  tickformatstops: array
  ticklabeloverflow: any
  ticklabelposition: any
  ticklabelstep: integer
  ticklen: number
  tickmode: any
  tickprefix: 'string' #(4)!
  ticks: any
  ticksuffix: 'string' #(5)!
  ticktext: array
  ticktextsrc: 'string' #(6)!
  tickvals: array
  tickvalssrc: 'string' #(7)!
  tickwidth: number
  title:
    font:
      color: any
      family: 'string' #(8)!
      lineposition: any
      shadow: 'string' #(9)!
      size: number
      style: any
      textcase: any
      variant: any
      weight: integer
    side: any
    text: 'string' #(10)!
  x: number
  xanchor: any
  xpad: number
  xref: any
  y: number
  yanchor: any
  ypad: number
  yref: any
colorscale: any
customdata: array
customdatasrc: 'string' #(11)!
featureidkey: 'string' #(12)!
geo: string
hoverinfo: array
hoverinfosrc: 'string' #(13)!
hoverlabel:
  align: array
  alignsrc: 'string' #(14)!
  bgcolor: array
  bgcolorsrc: 'string' #(15)!
  bordercolor: array
  bordercolorsrc: 'string' #(16)!
  font:
    color: array
    colorsrc: 'string' #(17)!
    family: 'string | array' #(18)!
    familysrc: 'string' #(19)!
    lineposition: array
    linepositionsrc: 'string' #(20)!
    shadow: 'string | array' #(21)!
    shadowsrc: 'string' #(22)!
    size: array
    sizesrc: 'string' #(23)!
    style: array
    stylesrc: 'string' #(24)!
    textcase: array
    textcasesrc: 'string' #(25)!
    variant: array
    variantsrc: 'string' #(26)!
    weight: array
    weightsrc: 'string' #(27)!
  namelength: array
  namelengthsrc: 'string' #(28)!
hovertemplate: 'string | array' #(29)!
hovertemplatesrc: 'string' #(30)!
hovertext: 'string | array' #(31)!
hovertextsrc: 'string' #(32)!
ids: array
idssrc: 'string' #(33)!
legend: string
legendgroup: 'string' #(34)!
legendgrouptitle:
  font:
    color: any
    family: 'string' #(35)!
    lineposition: any
    shadow: 'string' #(36)!
    size: number
    style: any
    textcase: any
    variant: any
    weight: integer
  text: 'string' #(37)!
legendrank: number
legendwidth: number
locationmode: any
locations: array
locationssrc: 'string' #(38)!
marker:
  line:
    color: array
    colorsrc: 'string' #(39)!
    width: array
    widthsrc: 'string' #(40)!
  opacity: array
  opacitysrc: 'string' #(41)!
metasrc: 'string' #(42)!
name: 'string' #(43)!
reversescale: boolean
selected:
  marker:
    opacity: number
showlegend: boolean
showscale: boolean
stream:
  maxpoints: number
  token: 'string' #(44)!
text: 'string | array' #(45)!
textsrc: 'string' #(46)!
type: choropleth
uid: 'string' #(47)!
unselected:
  marker:
    opacity: number
visible: any
z: array
zauto: boolean
zmax: number
zmid: number
zmin: number
zsrc: 'string' #(48)!
  1. 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.
  2. 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.
  3. 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
  4. Sets a tick label prefix.
  5. Sets a tick label suffix.
  6. Sets the source reference on Chart Studio Cloud for ticktext.
  7. Sets the source reference on Chart Studio Cloud for tickvals.
  8. 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.
  9. 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.
  10. Sets the title of the color bar.
  11. Sets the source reference on Chart Studio Cloud for customdata.
  12. Sets the key in GeoJSON features which is used as id to match the items included in the locations array. Only has an effect when geojson is set. Support nested property, for example properties.name.
  13. Sets the source reference on Chart Studio Cloud for hoverinfo.
  14. Sets the source reference on Chart Studio Cloud for align.
  15. Sets the source reference on Chart Studio Cloud for bgcolor.
  16. Sets the source reference on Chart Studio Cloud for bordercolor.
  17. Sets the source reference on Chart Studio Cloud for color.
  18. 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.
  19. Sets the source reference on Chart Studio Cloud for family.
  20. Sets the source reference on Chart Studio Cloud for lineposition.
  21. 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.
  22. Sets the source reference on Chart Studio Cloud for shadow.
  23. Sets the source reference on Chart Studio Cloud for size.
  24. Sets the source reference on Chart Studio Cloud for style.
  25. Sets the source reference on Chart Studio Cloud for textcase.
  26. Sets the source reference on Chart Studio Cloud for variant.
  27. Sets the source reference on Chart Studio Cloud for weight.
  28. Sets the source reference on Chart Studio Cloud for namelength.
  29. 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 in hovertemplate 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 are arrayOk: true) are available. 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>.
  30. Sets the source reference on Chart Studio Cloud for hovertemplate.
  31. Same as text.
  32. Sets the source reference on Chart Studio Cloud for hovertext.
  33. Sets the source reference on Chart Studio Cloud for ids.
  34. 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.
  35. 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.
  36. 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.
  37. Sets the title of the legend group.
  38. Sets the source reference on Chart Studio Cloud for locations.
  39. Sets the source reference on Chart Studio Cloud for color.
  40. Sets the source reference on Chart Studio Cloud for width.
  41. Sets the source reference on Chart Studio Cloud for opacity.
  42. Sets the source reference on Chart Studio Cloud for meta.
  43. Sets the trace name. The trace name appears as the legend item and on hover.
  44. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  45. Sets the text elements associated with each location.
  46. Sets the source reference on Chart Studio Cloud for text.
  47. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
  48. Sets the source reference on Chart Studio Cloud for z.