Using Plotly for a bar plot preserves the dataset's order when not using color
:
import pandas as pd
import plotly.express as px
df = pd.DataFrame({'val': [1, 2, 3],
'type': ['b', 'a', 'b']},
index=['obs1', 'obs2', 'obs3'])
px.bar(df, 'val')
px.bar(df, 'val', color='type')
How can I preserve the original ordering while using the color
arg?
This is similar to How can I retain desired order in R Plotly bar chart with color variable, but I'm using Python rather than R.