Multicategory for y-axis?

@Aire,

You can use multicategory for both x and y-axis, however for y-axis you may have to change the orientation of the bars to be horizontal. See the use of orientation='h' in the below example:

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Bar(
  x = [2, 3, 1, 5],
  y = [['First', 'First', 'Second', 'Second'],
       ["A", "B", "A", "B"]],
  name = "Adults",
  orientation='h'
))

fig.add_trace(go.Bar(
  x = [8, 3, 6, 5],
  y = [['First', 'First', 'Second', 'Second'],
       ["A", "B", "A", "B"]],
  name = "Children",
  orientation='h'
))

fig.update_layout(title_text="Multi-category axis")

fig.show()

And if you’d like the bars to be stacked, set barmode='stack' in the update_layout:

1 Like