Python - Plotly - Set range for x-axis when using facet_col

Histogram over all days of the week

Create histogram

fig=px.histogram(my_df,
x=‘hour_of_day’,
color=‘IDS’,
nbins=24,
facet_row=‘dst_country’,
facet_col=‘day_of_week’,
color_discrete_map={
“NORMAL”: “green”,
“SUSPICIOUS”: “yellow”,
“FRAUD”: “RED”},
category_orders={“day_of_week”: [“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”]},
title=“User xxx, Mondays, split on dst-country”)

remove day_of_the_week = and dst_country= from the labels

for annotation in fig.layout.annotations:
annotation.text = annotation.text.split("=")[1]

Set range for x-axis

fig.update_layout(xaxis=dict(range=[0,24]))
fig.show()

The problem is that I want the x-axis for all of my plots to be from 0 to 24. And I also want the y-axis shared. So that I can see where the really high counts are (right now the red one is 17 high, but you can only see that when you hover over it.) How can I set the x-range and share the y-axis?

The behaviour you’re seeing is actually a bug that we discovered very recently, and we hope to have a fix out in the next couple of weeks.

In the meantime you can use fig.update_yaxes() and fig.update_xaxes() to force the range to be whatever you specify across all x and y axes.