Sort values with an specific order multilevel X axis

Hello, I am using Plotly plot and I’m dealing with a multilevel x-axis visualization, is there a way to sort the values from both levels in a specific order:

Here is an example of what I’m trying to do:


Code:

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()

I want that the inner values are sorted in descending and outer values (BB,BB+) should take an inverse order meaning that BB should be in the first position and BB+ in the second one.

I managed to sort the dataset and it works but I am searching for a way to define the order directly because I’m dealing with a large dataset and I’m not able to sort the visualization with the order that I want, basically is taking random order in some cases