Multicategory Axis: How many categories are allowed?

Hi there

can I use mutlitcategory axis with more than two categories ?

I tried to enhance the previously posted example by adding an additional category (β€œ2020”) but only two (2020 and BB+/BB) are shown in the chart . Am I missing something or is it not possible to have more categories ?

Thanks !

import plotly.graph_objects as go
x = [[β€œ2020”, β€œ2020”, β€œ2020”, β€œ2020”, β€œ2020”, β€œ2020”],
[β€œBB+”, β€œBB+”, β€œBB+”, β€œBB”, β€œBB”, β€œBB”],
[16, 17, 18, 16, 17, 18,]
]
fig = go.Figure()
fig.add_bar(x=x,y=[1,2,3,4,5,6])
fig.add_bar(x=x,y=[6,5,4,3,2,1])
fig.update_layout(barmode=β€œrelative”)
fig.show()

Hi @sunshine, this is not possible at the moment with plotly. There is an open issue for this https://github.com/plotly/plotly.js/issues/2175 you can subscribe to the issue to get notified about future progress. Also if your organization has a software budget, sponsoring the development of a feature is possible. In the meantime you can probably add supplementary tick labels with annotations.

1 Like

I have just started with Plotly, saw this as a nice problem to try to tackle, and just posted the work so far. Available in https://codepen.io/richardnm-2/pen/RwyjMrB. Results with plotly.py at Extend multicategory axes to more than 2 levels Β· Issue #2175 Β· plotly/plotly.js Β· GitHub.
Maybe give it a try, let me know what you think of it!

2 Likes

HI @richardnm ,I see that you can achieve more than two x axis categories through js, but when I convert your js code to python code, I still can only show the first two categories, why? Thank you for your advice.

x1 = [
      1234, 1234, 1234, 2222, 3333, 4444, 4444, 2222, 3333, 4444, 4444, 1234,
      2222, 3333, 3333, 4444, 4444, 1234, 1234, 1234, 2222, 2222, 4444, 4444,
      4444
    ]

x2 = [
      1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.2, 1.25, 1.25, 1.25, 1.1, 1.1, 1.1,
      1.1, 1.1, 1.1, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.25
    ]

x3 = [
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
    ]

y = [
      74.7, 73.2, 73.1, 89.9, 87.0, 78.1,
      76.6, 85.8, 97.3, 76.7, 73.1, 68.8,
      79.3, 84.3, 82.5, 70.2, 72.2, 74.7,
      73.3, 70.0, 81.7, 84.7, 80.0, 82.2,
      74.7,
    ]

box = go.Box(x=[x1, x2, x3], y=y, boxpoints='all', jitter=0.3, pointpos=-1.8, marker={'color': "black", 'size': 5},
       line={'color': "red", 'width': 1}, fillcolor='white', whiskerwidth=1)
layout = go.Layout(paper_bgcolor='WhiteSmoke', plot_bgcolor='White')
go.Figure(data=box ,layout=layout).show()