Multiple x-axes with different ticks depending on zoom level

OK I managed to solve it myself, at least the part of showing multiple x-axes for day, and week number, without using multi-category.

See below for the code and an example. I created two additional dummy traces with associated x-axes: one for the week numbers and one for the dividers between weeks, for which I used long ticks. Also, I used a custom hovertemplate to assure that the full date is shown in the hover text.
Next step is to change the x-axes depending on the zoom-level, but that requires a dash-app, I think.

It works but it’s kind of hacky. If there’s a better way to do it I’d love to hear it.

cheers,
Maarten

import datetime as dt
import plotly.graph_objs as go
from scipy.stats import norm

nCategory = 5
nDays = 50

# generate bar data
base = dt.datetime.combine(dt.date.today(),dt.time(hour=12,minute=0))
date_list = [base + dt.timedelta(days=x) for x in range(nDays)]

barData = []
categoryLabels = []
barChart = []
for i in range(nCategory):
    barData = norm.rvs(4,1,nDays).tolist()
    barChart.append(go.Bar(x=date_list,y=barData, xaxis = 'x1',name = str(i), hovertemplate = '<b>%{x|%x}<br>%{y}<br></b>'))

# x-axis with day labels
xaxis1_vals = date_list
xaxis1_text = [d.strftime('%A')[0] for d in date_list]
xaxis1 = go.layout.XAxis(tickvals = xaxis1_vals,ticktext = xaxis1_text, showgrid = False)

# x-axis for the week numbers
dummyScatter1 = go.Scatter(x=date_list,y=[-1]*nDays, xaxis = 'x2',showlegend = False,hoverinfo='skip')

xaxis2_vals = [d for d in date_list if d.isoweekday()==3]
xaxis2 = go.layout.XAxis(matches = "x1",anchor="x1",overlaying="x1",ticklen = 30, 
                  ticks= 'outside',tickcolor = 'rgba(0,0,0,0)', tickformat = '%U',
                  tickvals = xaxis2_vals, showgrid = False)

# x-axis for the dividers between weeks
dummyScatter2 = go.Scatter(x=date_list,y=[-1]*nDays, xaxis = 'x3',showlegend = False,hoverinfo='skip')
xaxis3_vals = [d.date() for d in date_list if d.isoweekday()==7]
xaxis3_text = ['']*len(xaxis3_vals)
xaxis3 = go.layout.XAxis(matches = "x1",anchor="x1",overlaying="x1",ticklen = 50, 
                  ticks= 'outside', tickformat = '%U',

                  tickvals = xaxis3_vals, ticktext = xaxis3_text, showgrid = True, gridwidth=5)

yaxis = go.layout.YAxis(rangemode = 'nonnegative')

layout = go.Layout(xaxis=dict(), barmode = 'stack', xaxis1 = xaxis1, xaxis2 = xaxis2, xaxis3 = xaxis3, yaxis = yaxis, hovermode = 'x')

fig = go.Figure(data=barChart + [dummyScatter1,dummyScatter2],layout=layout)
fig.show()