Here's what I did so far:
import plotly.express as px
df = pd.read_parquet('so_sample.parquet')
df = df.groupby(['col1', 'col2']).size().reset_index(name='count')
px.bar(
df,
x='col1',
y='count',
color='col2',
).show()
I tried passing color_discrete_sequence=[color1, color2, ...]
and it doesn't make any difference.
CodePudding user response:
The data format used in matplotlib is wide format, but in plotly it is long format. plotly should be the same wide format and you can specify your favorite colormap. I chose Dark24, which has a large number of colors.
import plotly.express as px
import pandas as pd
df = pd.read_parquet('./data/so_sample.parquet')
#df = df.groupby(['col1', 'col2']).size().reset_index(name='count')
df = df.groupby(['col1', 'col2']).size().unstack().fillna(0)
px.bar(
df,
x=df.index,
y=df.columns.tolist(),
color_discrete_sequence=px.colors.qualitative.Dark24,
).show()