-
Notifications
You must be signed in to change notification settings - Fork 1
sankey nodes position #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ jupyter: | |
extension: .md | ||
format_name: markdown | ||
format_version: '1.1' | ||
jupytext_version: 1.1.1 | ||
jupytext_version: 1.2.1 | ||
kernel_info: | ||
name: python2 | ||
kernelspec: | ||
|
@@ -22,7 +22,7 @@ jupyter: | |
name: python | ||
nbconvert_exporter: python | ||
pygments_lexer: ipython3 | ||
version: 3.6.7 | ||
version: 3.7.3 | ||
plotly: | ||
description: How to make Sankey Diagrams in Python with Plotly. | ||
display_as: basic | ||
|
@@ -39,6 +39,7 @@ A [Sankey diagram](https://en.wikipedia.org/wiki/Sankey_diagram) is a flow diagr | |
|
||
|
||
### Basic Sankey Diagram | ||
Sankey diagrams visualize the contributions to a flow by defining [source](https://plot.ly/python/reference/#sankey-link-source) to represent the source node, [target](https://plot.ly/python/reference/#sankey-link-target) for the target node, [value](https://plot.ly/python/reference/#sankey-link-value) to set the flow volum, and [label](https://plot.ly/python/reference/#sankey-node-label) that shows the node name. | ||
|
||
```python | ||
import plotly.graph_objects as go | ||
|
@@ -64,6 +65,7 @@ fig.show() | |
### More complex Sankey diagram | ||
|
||
```python inputHidden=false outputHidden=false | ||
import plotly.graph_objects as go | ||
import urllib, json | ||
|
||
url = 'https://raw.githubusercontent.com/plotly/plotly.js/master/test/image/mocks/sankey_energy.json' | ||
|
@@ -96,6 +98,7 @@ fig.show() | |
### Style Sankey Diagram | ||
|
||
```python | ||
import plotly.graph_objects as go | ||
import urllib, json | ||
|
||
url = 'https://raw.githubusercontent.com/plotly/plotly.js/master/test/image/mocks/sankey_energy.json' | ||
|
@@ -129,6 +132,28 @@ fig.update_layout( | |
fig.show() | ||
``` | ||
|
||
### Define Node Position | ||
|
||
The following axample sets [node.x](https://plot.ly/python/reference/#sankey-node-x) and [node.y](https://plot.ly/python/reference/#sankey-node-y) to place nodes in the specified locations, except in the [snap arrangement](https://plot.ly/python/reference/#sankey-arrangement) to avoid overlapping of the nodes, therefore, an automatic snapping of elements will be set to define the padding between nodes via [nodepad](https://plot.ly/python/reference/#sankey-node-pad). The other possible arrangements are:<font color='blue'> 1)</font> perpendicular <font color='blue'>2)</font> freeform <font color='blue'>3)</font> fixed | ||
|
||
```python | ||
import plotly.graph_objects as go | ||
|
||
fig = go.Figure(go.Sankey( | ||
arrangement = "snap", | ||
node = { | ||
"label": ["A", "B", "C", "D", "E", "F"], | ||
"x": [0.2, 0.1, 0.5, 0.7, 0.3, 0.5], | ||
"y": [0.7, 0.5, 0.2, 0.4, 0.2, 0.3], | ||
'pad':10}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment before this line "pad is given in number of pixels" |
||
link = { | ||
"source": [0, 0, 1, 2, 5, 4, 3, 5], | ||
"target": [5, 3, 4, 3, 0, 2, 2, 3], | ||
"value": [1, 2, 1, 1, 1, 1, 1, 2]})) | ||
|
||
fig.show() | ||
``` | ||
|
||
### Reference | ||
|
||
See [https://plot.ly/python/reference/#sankey](https://plot.ly/python/reference/#sankey) for more information and options! |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the default value of
arrangement
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value for the arrangement is
snap
https://github.com/plotly/plotly.js/blob/f78f3cd3beee04db95aafcf9498031d112c87514/src/traces/sankey/attributes.js#L69-L81unless
node.x
andnode.y
are defined, then it'sfreeform
https://github.com/plotly/plotly.js/blob/f78f3cd3beee04db95aafcf9498031d112c87514/src/traces/sankey/defaults.js#L88-L92
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @antoinerg !