Sankey
Overview
The sankey
trace type is used to create Sankey diagrams, which visualize the flow of quantities between different nodes (or categories). Sankey diagrams are commonly used to show the transfer of resources or values, with the width of the flow lines being proportional to the size of the flow.
You can customize the colors, labels, and flow paths to represent your data and flows effectively.
Common Uses
- Flow of Resources: Visualizing how resources (e.g., money, energy, or materials) move between stages.
- Part-to-Part Relationships: Displaying how parts contribute to other parts rather than the whole.
- Energy or Supply Chains: Showing energy transfers or supply chain processes.
Check out the Attributes for the full set of configuration options
Examples
Common Configurations
Here's a simple sankey
diagram showing how values flow between different categories:
You can copy this code below to create this chart in your project:
models:
- name: sankey-data
args:
- echo
- |
source,target,value
0,1,10
0,2,5
1,3,15
2,3,5
traces:
- name: Simple Sankey Diagram
model: ${ref(sankey-data)}
props:
type: sankey
node:
label: ["A", "B", "C", "D"]
link:
source: ?{source}
target: ?{target}
value: ?{value}
charts:
- name: Simple Sankey Diagram
traces:
- ${ref(Simple Sankey Diagram)}
layout:
title:
text: Simple Sankey Diagram<br><sub>Flow of Resources Between Nodes</sub>
This example demonstrates a sankey
diagram with custom node and link colors:
Here's the code:
models:
- name: sankey-data-colors
args:
- echo
- |
source,target,value,color
0,1,10,#1f77b4
0,2,5,#ff7f0e
1,3,15,#2ca02c
2,3,5,#d62728
traces:
- name: Sankey Diagram with Custom Colors
model: ${ref(sankey-data-colors)}
props:
type: sankey
node:
label: ["X", "Y", "Z", "W"]
color: ?{color}
link:
source: ?{source}
target: ?{target}
value: ?{value}
charts:
- name: Sankey Diagram with Custom Colors
traces:
- ${ref(Sankey Diagram with Custom Colors)}
layout:
title:
text: Sankey Diagram with Custom Colors<br><sub>Custom Colors for Nodes and Links</sub>
This example shows a sankey
diagram where hover information displays both the value and the source-target relationship:
Here's the code:
models:
- name: sankey-data-hover
args:
- echo
- |
source,target,value
0,1,20
0,2,10
1,3,15
2,3,5
traces:
- name: Sankey Diagram with Hover Information
model: ${ref(sankey-data-hover)}
props:
type: sankey
node:
label: ["P", "Q", "R", "S"]
link:
source: ?{source}
target: ?{target}
value: ?{value}
hoverinfo: "source+target+value"
charts:
- name: Sankey Diagram with Hover Information
traces:
- ${ref(Sankey Diagram with Hover Information)}
layout:
title:
text: Sankey Diagram with Hover Information<br><sub>Hover Info Displaying Value and Relationships</sub>
A schema to validate plotly trace properties
Attributes
These attributes apply to traces where trace.props.type
is set to sankey
. You would configure these attributes on the trace with the trace.props
object.
arrangement: any
customdata: array
customdatasrc: 'string' #(1)!
domain:
column: integer
row: integer
x: array
y: array
hoverinfo: any
hoverlabel:
align: array
alignsrc: 'string' #(2)!
bgcolor: array
bgcolorsrc: 'string' #(3)!
bordercolor: array
bordercolorsrc: 'string' #(4)!
font:
color: array
colorsrc: 'string' #(5)!
family: 'string | array' #(6)!
familysrc: 'string' #(7)!
lineposition: array
linepositionsrc: 'string' #(8)!
shadow: 'string | array' #(9)!
shadowsrc: 'string' #(10)!
size: array
sizesrc: 'string' #(11)!
style: array
stylesrc: 'string' #(12)!
textcase: array
textcasesrc: 'string' #(13)!
variant: array
variantsrc: 'string' #(14)!
weight: array
weightsrc: 'string' #(15)!
namelength: array
namelengthsrc: 'string' #(16)!
ids: array
idssrc: 'string' #(17)!
legend: string
legendgrouptitle:
font:
color: any
family: 'string' #(18)!
lineposition: any
shadow: 'string' #(19)!
size: number
style: any
textcase: any
variant: any
weight: integer
text: 'string' #(20)!
legendrank: number
legendwidth: number
link:
arrowlen: number
color: array
colorscales: array
colorsrc: 'string' #(21)!
customdata: array
customdatasrc: 'string' #(22)!
hovercolor: array
hovercolorsrc: 'string' #(23)!
hoverinfo: any
hoverlabel:
align: array
alignsrc: 'string' #(24)!
bgcolor: array
bgcolorsrc: 'string' #(25)!
bordercolor: array
bordercolorsrc: 'string' #(26)!
font:
color: array
colorsrc: 'string' #(27)!
family: 'string | array' #(28)!
familysrc: 'string' #(29)!
lineposition: array
linepositionsrc: 'string' #(30)!
shadow: 'string | array' #(31)!
shadowsrc: 'string' #(32)!
size: array
sizesrc: 'string' #(33)!
style: array
stylesrc: 'string' #(34)!
textcase: array
textcasesrc: 'string' #(35)!
variant: array
variantsrc: 'string' #(36)!
weight: array
weightsrc: 'string' #(37)!
namelength: array
namelengthsrc: 'string' #(38)!
hovertemplate: 'string | array' #(39)!
hovertemplatesrc: 'string' #(40)!
label: array
labelsrc: 'string' #(41)!
line:
color: array
colorsrc: 'string' #(42)!
width: array
widthsrc: 'string' #(43)!
source: array
sourcesrc: 'string' #(44)!
target: array
targetsrc: 'string' #(45)!
value: array
valuesrc: 'string' #(46)!
metasrc: 'string' #(47)!
name: 'string' #(48)!
node:
align: any
color: array
colorsrc: 'string' #(49)!
customdata: array
customdatasrc: 'string' #(50)!
groups: array
hoverinfo: any
hoverlabel:
align: array
alignsrc: 'string' #(51)!
bgcolor: array
bgcolorsrc: 'string' #(52)!
bordercolor: array
bordercolorsrc: 'string' #(53)!
font:
color: array
colorsrc: 'string' #(54)!
family: 'string | array' #(55)!
familysrc: 'string' #(56)!
lineposition: array
linepositionsrc: 'string' #(57)!
shadow: 'string | array' #(58)!
shadowsrc: 'string' #(59)!
size: array
sizesrc: 'string' #(60)!
style: array
stylesrc: 'string' #(61)!
textcase: array
textcasesrc: 'string' #(62)!
variant: array
variantsrc: 'string' #(63)!
weight: array
weightsrc: 'string' #(64)!
namelength: array
namelengthsrc: 'string' #(65)!
hovertemplate: 'string | array' #(66)!
hovertemplatesrc: 'string' #(67)!
label: array
labelsrc: 'string' #(68)!
line:
color: array
colorsrc: 'string' #(69)!
width: array
widthsrc: 'string' #(70)!
pad: number
thickness: number
x: array
xsrc: 'string' #(71)!
y: array
ysrc: 'string' #(72)!
orientation: any
stream:
maxpoints: number
token: 'string' #(73)!
textfont:
color: any
family: 'string' #(74)!
lineposition: any
shadow: 'string' #(75)!
size: number
style: any
textcase: any
variant: any
weight: integer
type: sankey
uid: 'string' #(76)!
valueformat: 'string' #(77)!
valuesuffix: 'string' #(78)!
visible: any
- Sets the source reference on Chart Studio Cloud for
customdata
. - 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
. - Sets the source reference on Chart Studio Cloud for
ids
. - 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
color
. - Sets the source reference on Chart Studio Cloud for
customdata
. - Sets the source reference on Chart Studio Cloud for
hovercolor
. - 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. Variablessource
andtarget
are node objects.Finally, the template string has access to variablesvalue
andlabel
. 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 the source reference on Chart Studio Cloud for
label
. - 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
source
. - Sets the source reference on Chart Studio Cloud for
target
. - Sets the source reference on Chart Studio Cloud for
value
. - 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.
- Sets the source reference on Chart Studio Cloud for
color
. - Sets the source reference on Chart Studio Cloud for
customdata
. - 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. VariablessourceLinks
andtargetLinks
are arrays of link objects.Finally, the template string has access to variablesvalue
andlabel
. 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 the source reference on Chart Studio Cloud for
label
. - 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
x
. - Sets the source reference on Chart Studio Cloud for
y
. - The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
- 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.
- Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
- Sets the value 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.
- Adds a unit to follow the value in the hover tooltip. Add a space if a separation is necessary from the value.