-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Sorting issues with multicategories #1491
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
Comments
Thanks for the report @ThibTrip, I've opened plotly/plotly.js#3723 to discuss with the plotly.js team. |
Just dropping another example: Note the commented line in import pandas as pd
import plotly.graph_objects as go
data = [
[0, "Born", 4, "Rhino"], # commenting this line will also reverse sub category sorting
[0, "Died", -1, "Rhino"],
[1, "Born", 4, "Lion"],
[1, "Died", -1, "Lion"],
[2, "Born", 12, "Rhino"],
[2, "Died", -5, "Lion"],
]
z_data = list(zip(*data))
df = pd.DataFrame({
"tick": z_data[0],
"category": z_data[1],
"value": z_data[2],
"type": z_data[3],
})
df = df.sort_values(by=['tick', 'category', 'value', 'type'])
print(df)
fig = go.Figure()
for t in df.type.unique():
plot_df = df[df.type == t]
fig.add_trace(go.Bar(
x=[plot_df.tick, plot_df.category],
y=abs(plot_df.value),
name=t,
))
fig.update_layout({
'barmode': 'stack',
'xaxis': {
'title_text': "Tick",
'tickangle': -90,
},
'yaxis': {
'title_text': "Value",
},
})
fig.write_html(str("./diagram.html")) |
Hi - we are currently trying to tidy up Plotly's public repositories to help us focus our efforts on things that will help users most. Since this issue has been sitting for several years, I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our backlog. Thanks for your help - @gvwilson |
This is also a way to reduce the issue count. |
Hello,
as you can see here my chart is not correctly sorted by the x-axis and the line goes back which is really not an expected behavior.
I found out that a workaround is to add "missing" x labels (as in missing months in this case, see below) with None in y values but in my case it is very impractical.
First of all it will make the graph overly large (spans over 5 years in some cases but I do not have data for all months, far from that). Also I'm using this graph with dash and the data gets transformed a lot which makes adding missing labels quite tedious.
EDIT:
Another option you might think is to just use the month names in this case. Turns out that does not work either:
Thanks in advance for checking out the issue,
Thibault
Reproducible example with version 3.7.1 in offline mode
Related issue on plotly.js
The issue I'm describing here should have been fixed in version 1.43.1 of plotly.js.
See https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md#1431----2018-12-21
(issue 3362)
Even though plotly.py uses a superior version as you can see there is still an issue.
The text was updated successfully, but these errors were encountered: