I have a multi categorical y axis bar graph in plotly, and I need the order of the second y axis to be “Yours”, and then “National”. I cannot seem to change the order. “Category_order” is not changing anything unfortunately.
dfgraph77 = pd.DataFrame
fig = go.Figure()
fig.update_layout(
template="simple_white",
barmode="stack", title= f'<b>Graph 7: Job Role Ratio by Gender')
fig.update_layout(uniformtext_minsize=14, uniformtext_mode='hide', xaxis_title= None)
fig.update_layout(height=850, width=1340)
fig.update_yaxes(ticksuffix = " ")
fig.update_yaxes(tickformat=".0f")
fig.update_xaxes(ticksuffix='%')
fig.update_layout(yaxis={'categoryorder':'array', 'categoryarray':['Engagement','Cleaning','Support', 'Technology','Administration']})
fig.upate_yaxes(categoryorder='array, categoryarray=['Yours', 'National'])
fig.update_layout(
font_family="MS Sans Serif",
font_color="black",
title_font_family="MS Sans Serif",
title_font_color="black",
font_size=19,title_font_size=24,
legend_title_font_color="black",
legend_font_size=19
)
fig.update_layout(bargap=.1)
fig.update_layout(legend_traceorder="normal")
fig.update_layout(legend=dict(orientation='h'))
fig.update_layout(
margin=dict(l=15, r=20))
colors = ['#6C625A','#DCD3CB','#000000']
for r, c in zip(newgraph7.Gender.unique(), colors):
plot_df = newgraph7[newgraph7.Gender== r]
fig.add_trace(
go.Bar(y=[plot_df.Role, plot_df.Institution_name22], x=plot_df.percent, name=r, marker_color=c, orientation='h', text=plot_df['percent2'])
)
fig.update_traces(texttemplate="%{text}%")
fig.show()
I want the resulting image to look like this below, but with the “National”, and “Yours” bars switched. I had to cross some things out as this is for work. Any help is greatly appreciated!