Skip to content

Scattermapbox

Overview

The scattermapbox trace type is used to create scatter plots on a Mapbox map. This is ideal for visualizing geospatial data with the added customization and interactivity that Mapbox provides, including satellite imagery and street maps.

You can plot geographic points with latitude and longitude and customize the marker size, color, and labels to represent data effectively.

Common Uses

  • Geospatial Analysis: Plotting geographic points on an interactive map.
  • Location-Based Data: Visualizing locations and patterns on a Mapbox map.
  • Mapping Events: Plotting real-world events, like earthquakes or delivery points.

Check out the Attributes for the full set of configuration options

Examples

Common Configurations

Here's a simple scattermapbox plot showing data points on a Mapbox map:

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

models:
  - name: scattermapbox-data
    args:
      - echo
      - |
        lon,lat
        -73.9857,40.7484
        -118.2437,34.0522
        -0.1276,51.5074
        139.6917,35.6895
traces:
  - name: Simple Scattermapbox Plot
    model: ${ref(scattermapbox-data)}
    props:
      type: scattermapbox
      lon: ?{lon}
      lat: ?{lat}
      mode: "markers"
      marker:
        size: 10
charts:
  - name: Simple Scattermapbox Chart
    traces:
      - ${ref(Simple Scattermapbox Plot)}
    layout:
      mapbox:
        style: "open-street-map"
      title:
        text: Simple Scattermapbox Plot<br><sub>Geographical Data Points on Mapbox</sub>

This example demonstrates a scattermapbox plot with lines connecting geographic points:

Here's the code:

models:
  - name: scattermapbox-data-lines
    args:
      - echo
      - |
        lon,lat
        -73.9857,40.7484
        -118.2437,34.0522
        -0.1276,51.5074
        139.6917,35.6895
traces:
  - name: Scattermapbox Plot with Lines
    model: ${ref(scattermapbox-data-lines)}
    props:
      type: scattermapbox
      lon: ?{lon}
      lat: ?{lat}
      mode: "lines+markers"
      marker:
        size: 10
charts:
  - name: Scattermapbox Chart with Lines
    traces:
      - ${ref(Scattermapbox Plot with Lines)}
    layout:
      mapbox:
        style: "satellite-streets"
      title:
        text: Scattermapbox Plot with Lines<br><sub>Connecting Geographic Points on Mapbox</sub>

Here's a scattermapbox plot with custom marker sizes and colors, giving more visual weight to each geographic data point:

Here's the code:

models:
  - name: scattermapbox-data-custom
    args:
      - echo
      - |
        lon,lat,size,color
        -73.9857,40.7484,10,#1f77b4
        -118.2437,34.0522,15,#ff7f0e
        -0.1276,51.5074,20,#2ca02c
        139.6917,35.6895,25,#d62728
traces:
  - name: Scattermapbox Plot with Custom Markers
    model: ${ref(scattermapbox-data-custom)}
    props:
      type: scattermapbox
      lon: ?{lon}
      lat: ?{lat}
      mode: "markers"
      marker:
        size: ?{size}
        color: ?{color}
charts:
  - name: Scattermapbox Chart with Custom Markers
    traces:
      - ${ref(Scattermapbox Plot with Custom Markers)}
    layout:
      mapbox:
        style: "dark"
      title:
        text: Scattermapbox Plot with Custom Markers<br><sub>Custom Sizes and Colors for Geographic Data Points</sub>

A schema to validate plotly trace properties

Attributes

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

below: 'string' #(1)!
cluster:
  color: array
  colorsrc: 'string' #(2)!
  enabled: boolean
  maxzoom: number
  opacity: array
  opacitysrc: 'string' #(3)!
  size: array
  sizesrc: 'string' #(4)!
  step: array
  stepsrc: 'string' #(5)!
connectgaps: boolean
customdata: array
customdatasrc: 'string' #(6)!
fill: any
fillcolor: any
hoverinfo: array
hoverinfosrc: 'string' #(7)!
hoverlabel:
  align: array
  alignsrc: 'string' #(8)!
  bgcolor: array
  bgcolorsrc: 'string' #(9)!
  bordercolor: array
  bordercolorsrc: 'string' #(10)!
  font:
    color: array
    colorsrc: 'string' #(11)!
    family: 'string | array' #(12)!
    familysrc: 'string' #(13)!
    lineposition: array
    linepositionsrc: 'string' #(14)!
    shadow: 'string | array' #(15)!
    shadowsrc: 'string' #(16)!
    size: array
    sizesrc: 'string' #(17)!
    style: array
    stylesrc: 'string' #(18)!
    textcase: array
    textcasesrc: 'string' #(19)!
    variant: array
    variantsrc: 'string' #(20)!
    weight: array
    weightsrc: 'string' #(21)!
  namelength: array
  namelengthsrc: 'string' #(22)!
hovertemplate: 'string | array' #(23)!
hovertemplatesrc: 'string' #(24)!
hovertext: 'string | array' #(25)!
hovertextsrc: 'string' #(26)!
ids: array
idssrc: 'string' #(27)!
lat: array
latsrc: 'string' #(28)!
legend: string
legendgroup: 'string' #(29)!
legendgrouptitle:
  font:
    color: any
    family: 'string' #(30)!
    lineposition: any
    shadow: 'string' #(31)!
    size: number
    style: any
    textcase: any
    variant: any
    weight: integer
  text: 'string' #(32)!
legendrank: number
legendwidth: number
line:
  color: any
  width: number
lon: array
lonsrc: 'string' #(33)!
marker:
  allowoverlap: boolean
  angle: array
  anglesrc: 'string' #(34)!
  autocolorscale: boolean
  cauto: boolean
  cmax: number
  cmid: number
  cmin: number
  color: array
  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' #(35)!
      lineposition: any
      shadow: 'string' #(36)!
      size: number
      style: any
      textcase: any
      variant: any
      weight: integer
    tickformat: 'string' #(37)!
    tickformatstops: array
    ticklabeloverflow: any
    ticklabelposition: any
    ticklabelstep: integer
    ticklen: number
    tickmode: any
    tickprefix: 'string' #(38)!
    ticks: any
    ticksuffix: 'string' #(39)!
    ticktext: array
    ticktextsrc: 'string' #(40)!
    tickvals: array
    tickvalssrc: 'string' #(41)!
    tickwidth: number
    title:
      font:
        color: any
        family: 'string' #(42)!
        lineposition: any
        shadow: 'string' #(43)!
        size: number
        style: any
        textcase: any
        variant: any
        weight: integer
      side: any
      text: 'string' #(44)!
    x: number
    xanchor: any
    xpad: number
    xref: any
    y: number
    yanchor: any
    ypad: number
    yref: any
  colorscale: any
  colorsrc: 'string' #(45)!
  opacity: array
  opacitysrc: 'string' #(46)!
  reversescale: boolean
  showscale: boolean
  size: array
  sizemin: number
  sizemode: any
  sizeref: number
  sizesrc: 'string' #(47)!
  symbol: 'string | array' #(48)!
  symbolsrc: 'string' #(49)!
metasrc: 'string' #(50)!
mode: any
name: 'string' #(51)!
opacity: number
selected:
  marker:
    color: any
    opacity: number
    size: number
showlegend: boolean
stream:
  maxpoints: number
  token: 'string' #(52)!
subplot: string
text: 'string | array' #(53)!
textfont:
  color: any
  family: 'string' #(54)!
  size: number
  style: any
  weight: integer
textposition: any
textsrc: 'string' #(55)!
texttemplate: 'string | array' #(56)!
texttemplatesrc: 'string' #(57)!
type: scattermapbox
uid: 'string' #(58)!
unselected:
  marker:
    color: any
    opacity: number
    size: number
visible: any
  1. Determines if this scattermapbox trace's layers are to be inserted before the layer with the specified ID. By default, scattermapbox layers are inserted above all the base layers. To place the scattermapbox layers above every other layer, set below to ''.
  2. Sets the source reference on Chart Studio Cloud for color.
  3. Sets the source reference on Chart Studio Cloud for opacity.
  4. Sets the source reference on Chart Studio Cloud for size.
  5. Sets the source reference on Chart Studio Cloud for step.
  6. Sets the source reference on Chart Studio Cloud for customdata.
  7. Sets the source reference on Chart Studio Cloud for hoverinfo.
  8. Sets the source reference on Chart Studio Cloud for align.
  9. Sets the source reference on Chart Studio Cloud for bgcolor.
  10. Sets the source reference on Chart Studio Cloud for bordercolor.
  11. Sets the source reference on Chart Studio Cloud for color.
  12. 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.
  13. Sets the source reference on Chart Studio Cloud for family.
  14. Sets the source reference on Chart Studio Cloud for lineposition.
  15. 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.
  16. Sets the source reference on Chart Studio Cloud for shadow.
  17. Sets the source reference on Chart Studio Cloud for size.
  18. Sets the source reference on Chart Studio Cloud for style.
  19. Sets the source reference on Chart Studio Cloud for textcase.
  20. Sets the source reference on Chart Studio Cloud for variant.
  21. Sets the source reference on Chart Studio Cloud for weight.
  22. Sets the source reference on Chart Studio Cloud for namelength.
  23. 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>.
  24. Sets the source reference on Chart Studio Cloud for hovertemplate.
  25. 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.
  26. Sets the source reference on Chart Studio Cloud for hovertext.
  27. Sets the source reference on Chart Studio Cloud for ids.
  28. Sets the source reference on Chart Studio Cloud for lat.
  29. 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.
  30. 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.
  31. 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.
  32. Sets the title of the legend group.
  33. Sets the source reference on Chart Studio Cloud for lon.
  34. Sets the source reference on Chart Studio Cloud for angle.
  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 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
  38. Sets a tick label prefix.
  39. Sets a tick label suffix.
  40. Sets the source reference on Chart Studio Cloud for ticktext.
  41. Sets the source reference on Chart Studio Cloud for tickvals.
  42. 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.
  43. 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.
  44. Sets the title of the color bar.
  45. Sets the source reference on Chart Studio Cloud for color.
  46. Sets the source reference on Chart Studio Cloud for opacity.
  47. Sets the source reference on Chart Studio Cloud for size.
  48. Sets the marker symbol. Full list: https://www.mapbox.com/maki-icons/ Note that the array marker.color and marker.size are only available for circle symbols.
  49. Sets the source reference on Chart Studio Cloud for symbol.
  50. Sets the source reference on Chart Studio Cloud for meta.
  51. Sets the trace name. The trace name appears as the legend item and on hover.
  52. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  53. 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.
  54. 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.
  55. Sets the source reference on Chart Studio Cloud for text.
  56. Template string used for rendering the information text that appear on points. Note that this will override textinfo. Variables are inserted using %{variable}, for example "y: %{y}". 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. Every attributes that can be specified per-point (the ones that are arrayOk: true) are available. Finally, the template string has access to variables lat, lon and text.
  57. Sets the source reference on Chart Studio Cloud for texttemplate.
  58. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.