Let's suppose this is my dataset:
my_data = pd.DataFrame.from_dict({
'Countries':['Australia', 'Canada', 'China', 'Netherlands'],
'A':[1.89,1.45,1.22,0.94],
'B':[0.8,1,1.45,1.6]
})
I want to order the countries by the value of 'A' in both plots, but I tried a lot of things and just can't. I will be very grateful for any help.
This is my code:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import pandas as pd
fig = make_subplots(rows=1, cols=2)
fig.add_trace(
go.Bar(
x=my_data['A'],
y=my_data['Countries'],
orientation='h',
text = my_data['A'],
name = 'A'),
row=1, col=1
)
fig.add_trace(
go.Bar(
x=my_data['B'],
y=my_data['Countries'],
orientation='h',
text = my_data['B'],
name = 'B'),
row=1, col=2
)
fig.update_layout(barmode='stack', yaxis={'categoryorder':'total ascending'})
fig.update_layout(height=600, width=1000, title_text="Side By Side Subplots")
fig.show()

