Hi, I want to sort my grouped bar plots one-by-one in descending (question on StackOverflow) but didn’t find any solution, is this possible? (I’ve found that sorting particular traces is not possible).
Want to sort players first by their Weight, then by Height, and so on…
My Code
import pandas as pd
import numpy as np
import plotly.graph_objects as go
dftst = pd.DataFrame([('Arthur', 110, 200, 10),
('Benson', 50, 160, 12),
('Carlos', 90, 170, 14),
('Dante', 160, 180, 11),
('Evan', 130, 165, 18),
('Frank', 70, 190, 20)],
columns=('Name', 'Weight', 'Height', 'Score'))
pnames = dftst['Name']
x = list(range(len(pnames)))
bar_plots = [
go.Bar(x=x, y=dftst['Weight'], name='Weight', marker=go.bar.Marker(color='#0343df')),
go.Bar(x=x, y=dftst['Height'], name='Height', marker=go.bar.Marker(color='#e50000')),
go.Bar(x=x, y=dftst['Score'], name='Score', marker=go.bar.Marker(color='green')),
]
layout = go.Layout(
title=go.layout.Title(text="Players", x=0.5),
yaxis_title="Players Details",
xaxis_tickmode="array",
xaxis_tickvals=list(range(6)),
xaxis_ticktext=tuple(dftst['Name'].values))
fig = go.Figure(data=bar_plots, layout=layout)
fig.update_layout(
autosize=False,
width=600,
height=700)
fig.update_layout(barmode='group', xaxis={'categoryorder':'category ascending'})
fig.update_xaxes(
showgrid=True,
ticks="outside",
tickson="boundaries",
ticklen=20
)
fig.show()