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
- Scatter traces are also used to generate area and line traces.
- 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
- 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.
- Sets the source reference on Chart Studio Cloud for
customdata
. - Sets the source reference on Chart Studio Cloud for
arrayminus
. - Sets the source reference on Chart Studio Cloud for
array
. - Sets the source reference on Chart Studio Cloud for
arrayminus
. - Sets the source reference on Chart Studio Cloud for
array
. - Sets the source reference on Chart Studio Cloud for
bgcolor
. - Sets the source reference on Chart Studio Cloud for
fgcolor
. - Sets the source reference on Chart Studio Cloud for
shape
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
solidity
. - 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. 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
. - 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. - 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
backoff
. - 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).
- Sets the source reference on Chart Studio Cloud for
angle
. - 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
color
. - Sets the source reference on Chart Studio Cloud for
color
. - Sets the source reference on Chart Studio Cloud for
type
. - 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
size
. - Sets the source reference on Chart Studio Cloud for
standoff
. - Sets the source reference on Chart Studio Cloud for
symbol
. - 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.
- 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.
- 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 turnsfill
on by default, using tonexty (tonextx) iforientation
is h (v) and sets the defaultmode
to lines irrespective of point count. You can only stack on a numeric (linear or log) axis. Traces in astackgroup
will only fill to (or be filled to) other traces in the same group. With multiplestackgroup
s 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. - 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 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. - 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
textposition
. - Sets the source reference on Chart Studio Cloud for
text
. - 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 arearrayOk: true
) are available. - Sets the source reference on Chart Studio Cloud for
texttemplate
. - Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
- 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 usingxaxis.hoverformat
. - Sets the source reference on Chart Studio Cloud for
x
. - 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 usingyaxis.hoverformat
. - Sets the source reference on Chart Studio Cloud for
y
.