Boxplot with time xaxis plotting y as categorical

I’m trying to make a box plot with the following arrays

y = array([[16.2, 16.2, 16.2, ..., 15.9, 16.5, 15.5],
           [13.8, 14.8, 12.9, ..., 13.3, 16.1, 13.3]])
> y.shape = (110, 40)

x = array(['2023-08-03T08:00:00.000000000', '2023-08-03T09:00:00.000000000',
           '2023-08-07T20:00:00.000000000', '2023-08-07T21:00:00.000000000'],
> x.shape = (110,)

When doing the boxplot


The y axis is interpreted as categorical

I’ve checked that y has the correct numerical type and x is a datetime.

What am I doing wrong?

HI @guidocioni,

could you provide a MRE?

Hey, thanks for the reply.

I’m trying to structure a MRE but I haven’t had the time yet.

I think the problem stems from the fact that plotly does not interpret correctly the array N x M that I’m passing as y. I was under the impression that the default behaviour would be as in matplotlib: you pass a N array as x, an N x M array as y, and M boxplots will be constructed at N locations defined by x.

This is what I want to achieve (in matplotlib, forget about the grey line)

Is there any way to reproduce this in plotly with the arrays in the shape I have?

I had to trust ChatGPT for this one.

Suppose you have dataframe made like this

time temperature_2m temperature_2m_member01 temperature_2m_member02 temperature_2m_member03
2023-11-13 14:00:00+05:00 14.8 15.1 14.9 14.8
2023-11-13 15:00:00+05:00 15.4 15.8 15.5 15.4
2023-11-13 16:00:00+05:00 15.8 16.0 15.9 15.7
2023-11-13 17:00:00+05:00 15.6 15.9 15.8 15.6
2023-11-13 18:00:00+05:00 14.9 15.2 15.0 15.0

I can manually make a boxplot at every time step doing

fig = go.Figure()

for index, row in df.set_index('time').iterrows():
        x=[index] * len(row),

The xaxis created in this figure is a normal time axis, so it’s possible to use it for other scatter plots (what I wanted to do eventually).