plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
15.98k stars 2.53k forks source link

Improper Sankey rendering for certain minimal topologies with loops #3587

Open bkuczenski opened 2 years ago

bkuczenski commented 2 years ago

Sankey engine fails to correctly draw certain graphs containing loops. Attached is a minimal example containing 4 nodes and 5 traces. If any trace value is set to 0, the graph renders correctly.

Tested in python on plotly 5.5.0

import plotly.graph_objects as go
nodes = {'label': ['node 0', 'node 1', 'node 2', 'node 3']}
links = {'source': [0, 1, 2, 2, 3], 'target': [3, 0, 0, 3, 2], 'value': [1, 1, 1, 1, 1]}
go.Figure(go.Sankey(node=nodes, link=links)).show()

bad_sankey

In the correct rendering, the trace connecting node 2 to node 0 should be straight across.

This may be related to https://github.com/plotly/plotly.py/issues/3568

bkuczenski commented 2 years ago

Note: the bug seems to be dependent on the order of the traces. The following example has the same topology but renders correctly. Very mysterious!

import plotly.graph_objects as go
nodes = {'label': ['node 0', 'node 1', 'node 2', 'node 3']}
plinks = {'source': [2, 3, 0, 0, 1], 'target': [1, 2, 2, 1, 0], 'value': [1, 1, 1, 1, 1]}
go.Figure(go.Sankey(node=nodes, link=plinks)).show()

good_sankey