plotly / plotly.py

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

plotly.graph_objects.Sankey docs incorrectly indicates support for legends #2517

Open ned9 opened 4 years ago

ned9 commented 4 years ago

I'm trying to display a legend with a Sankey diagram. I gather this is intended to be possible as the docs state this for the name param for plotly.graph_objects.Sankey: Sets the trace name. The trace name appear as the legend item and on hover.

I can't see the legend appearing however, nor the trace name appearing on hover. The following example demonstrates the issue for me:

import plotly.graph_objects as go

go.Figure({
    'data': [
        {'link': {'source': [0, 0, 0, 1, 1, 1, 2, 2],
                  'target': [3, 4, 5, 3, 4, 5, 3, 5],
                  'value': [10, 20, 20, 10, 5, 5, 20, 10]},
              'name': 'Trace 1',
              'node': {'label': ["A", "B", "C", "D", "E", "F"]},
              'type': 'sankey'
             },
    ],
    'layout': {'showlegend': True}
})

I'm using Plotly 4.8.1.

I also came across this Stack Overflow question that makes me wonder if this person is experiencing the same issue as me.

nicolaskruchten commented 4 years ago

Unfortunately I think the legend doc entry is a little misleading in this case. It refers to what this attribute does for traces in general, when they support legends, but actually Sankey traces don't support legends at all. Sorry about the confusing docs, I'll see what we can do to fix them.

ineelshah commented 4 years ago

Unfortunately I think the legend doc entry is a little misleading in this case. It refers to what this attribute does for traces in general, when they support legends, but actually Sankey traces don't support legends at all. Sorry about the confusing docs, I'll see what we can do to fix them.

I can help to fix it. It looks like an easy issue to fix unless you think it is more complex than changing the explanation provided in the docs for "name", This can be a good first issue for me to solve. Just brief me about how to solve this. Can I work on it?

ned9 commented 4 years ago

Ah right, well that explains things. Thanks for clearing that up. So the name param does nothing for Sankey plots then?

nicolaskruchten commented 4 years ago

It doesn’t really do much, no. It’s a parameter that’s available for all traces for consistency but absent a legend it’s only visible in hoverlabels, and in the case of Sankey traces, by default it’s not even shown there.

nicolaskruchten commented 4 years ago

@ineelshah thanks for the enthusiasm! This particular issue is a bit tricky to resolve, as the Python code and documentation in question is auto-generated from the Javascript code in https://github.com/plotly/plotly.js

fstricker commented 2 years ago

Is this issue still unresolved? There are ways to bypass the problem when building a Dash app, but for standalone Plotly Sankey charts, this looks like a brutal show stopper.

maciejskorski commented 1 year ago

Any updates?

gvwilson commented 1 month ago

@LiamConnors is this still an issue?

LiamConnors commented 2 weeks ago

The documentation update is still an issue. It's not an easy one to resolve as the the documentation is autogenerated from Plotly.js and probably requires some updates to Plotly.js.