Multicategory Axis Type Example?

I could not find any documentation on how to generate a plot similar to
the example:

Could someone be kind enough to share an example?

The only reference I could find was the GitHub issue: https://github.com/plotly/plotly.js/issues/2799

Thanks, but the first link seems to just be a stacked bar chart with a single x-axis category. I’m trying to replicate an x-axis like the one above in my image with [16,17,18] as a subcategory of [BB+].

I found the same reference in the second link but I am still confused as to how to make it work.

Here’s a simple example:

import plotly.graph_objects as go
x = [
    ["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()

image

2 Likes

Good grief I can be dense at times. Thanks for spelling it out for me. I thought I had to explicitly make it a ‘multicategory’ axis, turns out I just hadn’t tried sending it a list of lists. Thanks!

1 Like

Ah, well our docs could be more explicit for sure! Under the hood, if your traces have arrays for x or y then the axis type is automatically inferred to be multicategory but you can also force it if you like.

1 Like

I think this is a bug:

When I create a chart using this method, the left and right-most x axis tick marks are offset by one:

This is the same chart zoomed in (the tick marks are still offset from the edges even though they should be at the edges or not present at all.)

Sorry for the long delay, I just saw this… it does seem like a bug!