Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Grouped and stacked xaxis labeling issue

I am attempting to create a grouped and stacked barplot with plotly express. I have had luck using this approach with a different data set, but this one has the caveat that the column in the dataframe that I am using as the x-axis is (seemingly) numberical. I converted the entire column to strings in pandas, which was the input to plotly, but plotly wants to reformat. I googled it to death and applied the standard fix to layout as such:

fig.update_layout(xaxis={‘type’: ‘category’})

However, it is only applying to the first of the subplots. The remainder of the subplots are being converted to floats. Is there a way to apply the layout change such that it implements the change to all auto-generated subplots by plotly express? I am pasting the code I used to generate the stacked/grouped subplots using a tidy dataframe. I attached image, but it’s unclear if it worked. Suffice to say, the first subplot is labeled as a string, but the next subplot is labeled as a float even though I explicitly converted the column to strings.

fig =, x=‘index’, y=‘RelAb’, barmode=‘stack’, color=‘SpeciesTruncated’, facet_col=‘Patient’)
fig.update_layout(xaxis={‘type’: ‘category’})