Closed

Description
Hello,
When using update_xaxes(categoryorder="total descending")
on a histogram, I expect the bars to be reordered by size.
The following example, tested in a Notebook, will not work according to my expectation:
import pandas as pd
import plotly.express as px
data =[['A','left'],['B','left'],['C','right'],['D','up'],['E','right'],['F','down'],
['A','right'],['B','righ'],['B','right'],['B','up'],['A','left'],['F','up'],
['B','left'],['F','left'],['B','right'],['A','up'],['A','right'],['F','down'],
]
df = pd.DataFrame(data, columns=['letter','direction'])
px.histogram(df, x='letter', color='direction').update_xaxes(categoryorder="total descending")
Note that the behavior is unclear to me. In certain condition, the order might be correct. For instance, if you change the last row to ['E','down']
, then the order of the plot is correct.
In any case, I would expect the same result than the following:
import pandas as pd
import plotly.express as px
data =[['A','left'],['B','left'],['C','right'],['D','up'],['E','right'],['F','down'],
['A','right'],['B','righ'],['B','right'],['B','up'],['A','left'],['F','up'],
['B','left'],['F','left'],['B','right'],['A','up'],['A','right'],['E','down'],
]
df = pd.DataFrame(data, columns=['letter','direction'])
df['count'] = 1
df = df.groupby(['letter','direction'])['count'].sum().reset_index()
px.bar(df, x='letter', y='count', color='direction').update_xaxes(categoryorder="total descending")
Metadata
Metadata
Assignees
Labels
No labels