Skip to content

Densitymapbox

Overview

The densitymapbox trace type is used to create density maps on a Mapbox layer. This is commonly used to visualize the density of points in a geographical area. Density maps can help in identifying hotspots or areas with a higher concentration of data points.

You can customize the colorscale, radius of influence for each point, and other properties to fine-tune the visualization.

Common Uses

  • Geospatial Data Analysis: Identifying hotspots in geographic data, such as crime rates or customer locations.
  • Event Density: Visualizing the concentration of events or occurrences across regions.
  • Heatmap for Geographic Points: Creating heatmaps based on spatial data distributions on a map.

Check out the Attributes for the full set of configuration options

Examples

Common Configurations

Here's a simple densitymapbox plot showing the density of random points on a Mapbox map:

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

models:
  - name: densitymapbox-data
    args:
      - echo
      - |
        lat,lon
        37.7749,-122.4194
        34.0522,-118.2437
        40.7128,-74.0060
        41.8781,-87.6298
        29.7604,-95.3698
traces:
  - name: Simple Densitymapbox Plot
    model: ${ref(densitymapbox-data)}
    props:
      type: densitymapbox
      lat: ?{lat}
      lon: ?{lon}
      radius: 10
      colorscale: "Viridis"
      zmin: 0
      zmax: 100
charts:
  - name: Simple Densitymapbox Chart
    traces:
      - ${ref(Simple Densitymapbox Plot)}
    layout:
      title:
        text: Simple Densitymapbox Plot<br><sub>Spatial Data Density</sub>
      mapbox:
        style: "carto-positron"
        zoom: 3
        center:
          lat: 37
          lon: -95

This example demonstrates a densitymapbox plot with a custom radius for the points, which influences how smooth the heatmap appears:

Here's the code:

models:
  - name: densitymapbox-data-radius
    args:
      - echo
      - |
        lat,lon
        51.5074,-0.1278
        48.8566,2.3522
        52.5200,13.4050
        40.7128,-74.0060
        34.0522,-118.2437
traces:
  - name: Densitymapbox with Custom Radius
    model: ${ref(densitymapbox-data-radius)}
    props:
      type: densitymapbox
      lat: ?{lat}
      lon: ?{lon}
      radius: 20
      colorscale: "Jet"
      zmin: 0
      zmax: 50
charts:
  - name: Densitymapbox Chart with Custom Radius
    traces:
      - ${ref(Densitymapbox with Custom Radius)}
    layout:
      title:
        text: Densitymapbox Plot with Custom Radius<br><sub>Radius of Influence on Heatmap</sub>
      mapbox:
        style: "carto-darkmatter"
        zoom: 2
        center:
          lat: 50
          lon: 0

This example shows a densitymapbox plot with a custom colorscale and zoom centered on Europe:

Here's the code:

models:
  - name: densitymapbox-data-colorscale
    args:
      - echo
      - |
        lat,lon
        48.8566,2.3522
        41.9028,12.4964
        52.3676,4.9041
        40.4168,-3.7038
        51.1657,10.4515
traces:
  - name: Densitymapbox with Custom Colorscale
    model: ${ref(densitymapbox-data-colorscale)}
    props:
      type: densitymapbox
      lat: ?{lat}
      lon: ?{lon}
      radius: 15
      colorscale: [[0, "rgb(255,245,240)"], [0.5, "rgb(252,146,114)"], [1, "rgb(165,15,21)"]]
      zmin: 0
      zmax: 50
charts:
  - name: Densitymapbox Chart with Custom Colorscale
    traces:
      - ${ref(Densitymapbox with Custom Colorscale)}
    layout:
      title:
        text: Densitymapbox Plot with Custom Colorscale<br><sub>Custom Coloring and Center</sub>
      mapbox:
        style: "carto-positron"
        zoom: 4
        center:
          lat: 48
          lon: 3

A schema to validate plotly trace properties

Attributes

These attributes apply to traces where trace.props.type is set to densitymapbox. 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)!
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)!
lat: array
latsrc: '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
lon: array
lonsrc: 'string' #(39)!
metasrc: 'string' #(40)!
name: 'string' #(41)!
opacity: number
radius: array
radiussrc: 'string' #(42)!
reversescale: boolean
showlegend: boolean
showscale: boolean
stream:
  maxpoints: number
  token: 'string' #(43)!
subplot: string
text: 'string | array' #(44)!
textsrc: 'string' #(45)!
type: densitymapbox
uid: 'string' #(46)!
visible: any
z: array
zauto: boolean
zmax: number
zmid: number
zmin: number
zsrc: 'string' #(47)!
  1. Determines if the densitymapbox trace will be inserted before the layer with the specified ID. By default, densitymapbox traces are placed below the first layer of type symbol If set to '', the layer will be inserted above every existing layer.
  2. 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.
  3. 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.
  4. 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
  5. Sets a tick label prefix.
  6. Sets a tick label suffix.
  7. Sets the source reference on Chart Studio Cloud for ticktext.
  8. Sets the source reference on Chart Studio Cloud for tickvals.
  9. 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.
  10. 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.
  11. Sets the title of the color bar.
  12. Sets the source reference on Chart Studio Cloud for customdata.
  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. Sets hover text elements associated with each (lon,lat) pair If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (lon,lat) coordinates. To be seen, trace hoverinfo must contain a text flag.
  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 source reference on Chart Studio Cloud for lat.
  35. 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.
  36. 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.
  37. 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.
  38. Sets the title of the legend group.
  39. Sets the source reference on Chart Studio Cloud for lon.
  40. Sets the source reference on Chart Studio Cloud for meta.
  41. Sets the trace name. The trace name appears as the legend item and on hover.
  42. Sets the source reference on Chart Studio Cloud for radius.
  43. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  44. Sets text elements associated with each (lon,lat) pair If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (lon,lat) coordinates. If trace hoverinfo contains a text flag and hovertext is not set, these elements will be seen in the hover labels.
  45. Sets the source reference on Chart Studio Cloud for text.
  46. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
  47. Sets the source reference on Chart Studio Cloud for z.