Skip to content

Scatter (line, area & scatter)

Overview

The scatter trace type is used to create scatter plots, which visualize data points based on two numerical variables. Scatter plots are widely used for analyzing relationships between variables, identifying trends, and detecting outliers.

Gotchas

  1. Scatter traces are also used to generate area and line traces.
  2. The line connections of a scatter trace are determined by the trace.order_by attribute. Make sure to set that to get a deterministic trace for lines and area permutations.

You can customize the marker size, color, and add lines to connect the points to represent the data in various forms like scatter plots, line charts, and more.

Common Uses

  • Relationship Analysis: Exploring the relationship between two variables.
  • Trend Detection: Identifying trends or patterns in data.
  • Outlier Identification: Spotting outliers in data distributions.

Check out the Attributes for the full set of configuration options

Examples

Common Configurations

Here's a simple scatter plot showing data points on a 2D plane:

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

models:
  - name: scatter-data
    args:
      - echo
      - |
        x,y
        1,10
        2,20
        3,15
        4,25
        5,30
        1.5,5
        2.5,22
        3.5,9
        4.5,21
        5.5,15

traces:
  - name: Simple Scatter Plot
    model: ${ref(scatter-data)}
    props:
      type: scatter
      x: ?{x}
      y: ?{y}
      mode: "markers"
      marker: 
        size: 10
    order_by: 
      - ?{x asc}
charts:
  - name: Simple Scatter Chart
    traces:
      - ${ref(Simple Scatter Plot)}
    layout:
      title:
        text: Simple Scatter Plot<br><sub>2D Data Points</sub>

This example demonstrates a scatter plot with lines connecting the data points to show trends:

Here's the code:

models:
  - name: scatter-data-lines
    args:
      - echo
      - |
        x,y
        1,5
        2,10
        3,8
        4,15
        5,12
traces:
  - name: Markers and Line
    model: ${ref(scatter-data-lines)}
    props:
      type: scatter
      x: ?{x}
      y: ?{y}
      mode: "lines+markers"
    order_by: 
      - ?{x asc}
  - name: Spline No Markers
    model: ${ref(scatter-data-lines)}
    props:
      type: scatter
      x: ?{x+3 - (x*x)/3}
      y: ?{y*1.5}
      mode: "lines"
      line: 
        shape: spline
        smoothing: .5 #Sets spline bend
    order_by: 
      - ?{x+3 - (x*x)/3}
charts:
  - name: Scatter Chart with Lines
    traces:
      - ${ref(Markers and Line)}
      - ${ref(Spline No Markers)}
    layout:
      title:
        text: Scatter Plot with Lines<br><sub>Connecting Data Points with Lines</sub>
      legend: 
        orientation: h

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

Here's the code:

models:
  - name: scatter-data-custom
    args:
      - echo
      - |
        x,y,size,color
        1,5,10,#1f77b4
        2,10,15,#ff7f0e
        3,8,20,#2ca02c
        4,15,25,#d62728
        5,12,30,#9467bd
traces:
  - name: Scatter Plot with Custom Markers
    model: ${ref(scatter-data-custom)}
    props:
      type: scatter
      x: ?{x}
      y: ?{y}
      mode: "markers"
      marker:
        size: ?{size}
        color: ?{color}
    order_by: 
      - ?{x asc}
charts:
  - name: Scatter Chart with Custom Markers
    traces:
      - ${ref(Scatter Plot with Custom Markers)}
    layout:
      title:
        text: Scatter Plot with Custom Markers<br><sub>Custom Sizes and Colors for Data Points</sub>

Here's a scatter plot used to create an area plot, filling the area under the line:

Here's the code:

models:
  - name: area-plot-data
    args:
      - echo
      - |
        x,y
        1,5
        2,7
        3,10
        4,8
        5,12
        6,9
        7,11
traces:
  - name: Area Plot
    model: ${ref(area-plot-data)}
    props:
      type: scatter
      x: ?{x}
      y: ?{y}
      mode: "lines"
      fill: "tozeroy"
      fillcolor: "rgba(55, 126, 184, 0.2)"
      line:
        color: "rgb(55, 126, 184)"
        width: 2
    order_by: 
      - ?{x asc}
charts:
  - name: Area Plot Chart
    traces:
      - ${ref(Area Plot)}
    layout:
      title:
        text: Area Plot<br><sub>Filled Area Under the Line</sub>

A schema to validate plotly trace properties

Attributes

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

alignmentgroup: 'string' #(1)!
cliponaxis: boolean
connectgaps: boolean
customdata: array
customdatasrc: 'string' #(2)!
dx: number
dy: number
error_x:
  array: array
  arrayminus: array
  arrayminussrc: 'string' #(3)!
  arraysrc: 'string' #(4)!
  color: any
  copy_ystyle: boolean
  symmetric: boolean
  thickness: number
  traceref: integer
  tracerefminus: integer
  type: any
  value: number
  valueminus: number
  visible: boolean
  width: number
error_y:
  array: array
  arrayminus: array
  arrayminussrc: 'string' #(5)!
  arraysrc: 'string' #(6)!
  color: any
  symmetric: boolean
  thickness: number
  traceref: integer
  tracerefminus: integer
  type: any
  value: number
  valueminus: number
  visible: boolean
  width: number
fill: any
fillcolor: any
fillgradient:
  colorscale: any
  start: number
  stop: number
  type: any
fillpattern:
  bgcolor: array
  bgcolorsrc: 'string' #(7)!
  fgcolor: array
  fgcolorsrc: 'string' #(8)!
  fgopacity: number
  fillmode: any
  shape: array
  shapesrc: 'string' #(9)!
  size: array
  sizesrc: 'string' #(10)!
  solidity: array
  soliditysrc: 'string' #(11)!
groupnorm: any
hoverinfo: array
hoverinfosrc: 'string' #(12)!
hoverlabel:
  align: array
  alignsrc: 'string' #(13)!
  bgcolor: array
  bgcolorsrc: 'string' #(14)!
  bordercolor: array
  bordercolorsrc: 'string' #(15)!
  font:
    color: array
    colorsrc: 'string' #(16)!
    family: 'string | array' #(17)!
    familysrc: 'string' #(18)!
    lineposition: array
    linepositionsrc: 'string' #(19)!
    shadow: 'string | array' #(20)!
    shadowsrc: 'string' #(21)!
    size: array
    sizesrc: 'string' #(22)!
    style: array
    stylesrc: 'string' #(23)!
    textcase: array
    textcasesrc: 'string' #(24)!
    variant: array
    variantsrc: 'string' #(25)!
    weight: array
    weightsrc: 'string' #(26)!
  namelength: array
  namelengthsrc: 'string' #(27)!
hoveron: string
hovertemplate: 'string | array' #(28)!
hovertemplatesrc: 'string' #(29)!
hovertext: 'string | array' #(30)!
hovertextsrc: 'string' #(31)!
ids: array
idssrc: 'string' #(32)!
legend: string
legendgroup: 'string' #(33)!
legendgrouptitle:
  font:
    color: any
    family: 'string' #(34)!
    lineposition: any
    shadow: 'string' #(35)!
    size: number
    style: any
    textcase: any
    variant: any
    weight: integer
  text: 'string' #(36)!
legendrank: number
legendwidth: number
line:
  backoff: array
  backoffsrc: 'string' #(37)!
  color: any
  dash: 'string' #(38)!
  shape: any
  simplify: boolean
  smoothing: number
  width: number
marker:
  angle: array
  angleref: any
  anglesrc: 'string' #(39)!
  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' #(40)!
      lineposition: any
      shadow: 'string' #(41)!
      size: number
      style: any
      textcase: any
      variant: any
      weight: integer
    tickformat: 'string' #(42)!
    tickformatstops: array
    ticklabeloverflow: any
    ticklabelposition: any
    ticklabelstep: integer
    ticklen: number
    tickmode: any
    tickprefix: 'string' #(43)!
    ticks: any
    ticksuffix: 'string' #(44)!
    ticktext: array
    ticktextsrc: 'string' #(45)!
    tickvals: array
    tickvalssrc: 'string' #(46)!
    tickwidth: number
    title:
      font:
        color: any
        family: 'string' #(47)!
        lineposition: any
        shadow: 'string' #(48)!
        size: number
        style: any
        textcase: any
        variant: any
        weight: integer
      side: any
      text: 'string' #(49)!
    x: number
    xanchor: any
    xpad: number
    xref: any
    y: number
    yanchor: any
    ypad: number
    yref: any
  colorscale: any
  colorsrc: 'string' #(50)!
  gradient:
    color: array
    colorsrc: 'string' #(51)!
    type: array
    typesrc: 'string' #(52)!
  line:
    autocolorscale: boolean
    cauto: boolean
    cmax: number
    cmid: number
    cmin: number
    color: array
    coloraxis: string
    colorscale: any
    colorsrc: 'string' #(53)!
    reversescale: boolean
    width: array
    widthsrc: 'string' #(54)!
  maxdisplayed: number
  opacity: array
  opacitysrc: 'string' #(55)!
  reversescale: boolean
  showscale: boolean
  size: array
  sizemin: number
  sizemode: any
  sizeref: number
  sizesrc: 'string' #(56)!
  standoff: array
  standoffsrc: 'string' #(57)!
  symbol: array
  symbolsrc: 'string' #(58)!
metasrc: 'string' #(59)!
mode: any
name: 'string' #(60)!
offsetgroup: 'string' #(61)!
opacity: number
orientation: any
selected:
  marker:
    color: any
    opacity: number
    size: number
  textfont:
    color: any
showlegend: boolean
stackgaps: any
stackgroup: 'string' #(62)!
stream:
  maxpoints: number
  token: 'string' #(63)!
text: 'string | array' #(64)!
textfont:
  color: array
  colorsrc: 'string' #(65)!
  family: 'string | array' #(66)!
  familysrc: 'string' #(67)!
  lineposition: array
  linepositionsrc: 'string' #(68)!
  shadow: 'string | array' #(69)!
  shadowsrc: 'string' #(70)!
  size: array
  sizesrc: 'string' #(71)!
  style: array
  stylesrc: 'string' #(72)!
  textcase: array
  textcasesrc: 'string' #(73)!
  variant: array
  variantsrc: 'string' #(74)!
  weight: array
  weightsrc: 'string' #(75)!
textposition: array
textpositionsrc: 'string' #(76)!
textsrc: 'string' #(77)!
texttemplate: 'string | array' #(78)!
texttemplatesrc: 'string' #(79)!
type: scatter
uid: 'string' #(80)!
unselected:
  marker:
    color: any
    opacity: number
    size: number
  textfont:
    color: any
visible: any
x: array
xaxis: string
xcalendar: any
xhoverformat: 'string' #(81)!
xperiodalignment: any
xsrc: 'string' #(82)!
y: array
yaxis: string
ycalendar: any
yhoverformat: 'string' #(83)!
yperiodalignment: any
ysrc: 'string' #(84)!
zorder: integer
  1. Set several traces linked to the same position axis or matching axes to the same alignmentgroup. This controls whether bars compute their positional range dependently or independently.
  2. Sets the source reference on Chart Studio Cloud for customdata.
  3. Sets the source reference on Chart Studio Cloud for arrayminus.
  4. Sets the source reference on Chart Studio Cloud for array.
  5. Sets the source reference on Chart Studio Cloud for arrayminus.
  6. Sets the source reference on Chart Studio Cloud for array.
  7. Sets the source reference on Chart Studio Cloud for bgcolor.
  8. Sets the source reference on Chart Studio Cloud for fgcolor.
  9. Sets the source reference on Chart Studio Cloud for shape.
  10. Sets the source reference on Chart Studio Cloud for size.
  11. Sets the source reference on Chart Studio Cloud for solidity.
  12. Sets the source reference on Chart Studio Cloud for hoverinfo.
  13. Sets the source reference on Chart Studio Cloud for align.
  14. Sets the source reference on Chart Studio Cloud for bgcolor.
  15. Sets the source reference on Chart Studio Cloud for bordercolor.
  16. Sets the source reference on Chart Studio Cloud for color.
  17. 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.
  18. Sets the source reference on Chart Studio Cloud for family.
  19. Sets the source reference on Chart Studio Cloud for lineposition.
  20. 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.
  21. Sets the source reference on Chart Studio Cloud for shadow.
  22. Sets the source reference on Chart Studio Cloud for size.
  23. Sets the source reference on Chart Studio Cloud for style.
  24. Sets the source reference on Chart Studio Cloud for textcase.
  25. Sets the source reference on Chart Studio Cloud for variant.
  26. Sets the source reference on Chart Studio Cloud for weight.
  27. Sets the source reference on Chart Studio Cloud for namelength.
  28. 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>.
  29. Sets the source reference on Chart Studio Cloud for hovertemplate.
  30. Sets hover text elements associated with each (x,y) 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 (x,y) coordinates. To be seen, trace hoverinfo must contain a text flag.
  31. Sets the source reference on Chart Studio Cloud for hovertext.
  32. Sets the source reference on Chart Studio Cloud for ids.
  33. 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.
  34. 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.
  35. 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.
  36. Sets the title of the legend group.
  37. Sets the source reference on Chart Studio Cloud for backoff.
  38. Sets the dash style of lines. Set to a dash type string (solid, dot, dash, longdash, dashdot, or longdashdot) or a dash length list in px (eg 5px,10px,2px,2px).
  39. Sets the source reference on Chart Studio Cloud for angle.
  40. 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.
  41. 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.
  42. 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
  43. Sets a tick label prefix.
  44. Sets a tick label suffix.
  45. Sets the source reference on Chart Studio Cloud for ticktext.
  46. Sets the source reference on Chart Studio Cloud for tickvals.
  47. 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.
  48. 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.
  49. Sets the title of the color bar.
  50. Sets the source reference on Chart Studio Cloud for color.
  51. Sets the source reference on Chart Studio Cloud for color.
  52. Sets the source reference on Chart Studio Cloud for type.
  53. Sets the source reference on Chart Studio Cloud for color.
  54. Sets the source reference on Chart Studio Cloud for width.
  55. Sets the source reference on Chart Studio Cloud for opacity.
  56. Sets the source reference on Chart Studio Cloud for size.
  57. Sets the source reference on Chart Studio Cloud for standoff.
  58. Sets the source reference on Chart Studio Cloud for symbol.
  59. Sets the source reference on Chart Studio Cloud for meta.
  60. Sets the trace name. The trace name appears as the legend item and on hover.
  61. Set several traces linked to the same position axis or matching axes to the same offsetgroup where bars of the same position coordinate will line up.
  62. Set several scatter traces (on the same subplot) to the same stackgroup in order to add their y values (or their x values if orientation is h). If blank or omitted this trace will not be stacked. Stacking also turns fill on by default, using tonexty (tonextx) if orientation is h (v) and sets the default mode to lines irrespective of point count. You can only stack on a numeric (linear or log) axis. Traces in a stackgroup will only fill to (or be filled to) other traces in the same group. With multiple stackgroups or some traces stacked and some not, if fill-linked traces are not already consecutive, the later ones will be pushed down in the drawing order.
  63. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  64. Sets text elements associated with each (x,y) 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 (x,y) coordinates. If trace hoverinfo contains a text flag and hovertext is not set, these elements will be seen in the hover labels.
  65. Sets the source reference on Chart Studio Cloud for color.
  66. 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.
  67. Sets the source reference on Chart Studio Cloud for family.
  68. Sets the source reference on Chart Studio Cloud for lineposition.
  69. 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.
  70. Sets the source reference on Chart Studio Cloud for shadow.
  71. Sets the source reference on Chart Studio Cloud for size.
  72. Sets the source reference on Chart Studio Cloud for style.
  73. Sets the source reference on Chart Studio Cloud for textcase.
  74. Sets the source reference on Chart Studio Cloud for variant.
  75. Sets the source reference on Chart Studio Cloud for weight.
  76. Sets the source reference on Chart Studio Cloud for textposition.
  77. Sets the source reference on Chart Studio Cloud for text.
  78. 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.
  79. Sets the source reference on Chart Studio Cloud for texttemplate.
  80. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
  81. Sets the hover text formatting rulefor x 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.46By default the values are formatted using xaxis.hoverformat.
  82. Sets the source reference on Chart Studio Cloud for x.
  83. Sets the hover text formatting rulefor y 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.46By default the values are formatted using yaxis.hoverformat.
  84. Sets the source reference on Chart Studio Cloud for y.