Plolty date xaxis Pretty Date formatting with boundaries

image
Can you help me achieve similar to the image? What I want is the date will be separated by a vertical line that will act as boundary between two months and possibly the month is located on the center?

Here is my code for my go.figure:

fig = go.Figure(data=mydata)
fig.update_xaxes(dtick=86400000,tickformat="%d\n%b",ticks="inside",ticklen=5)
fig.update_yaxes(range=[min, max], ticks="inside",dtick="200") #range=[yaxis_min, yaxis_max], 
fig.update_layout(legend=dict(orientation='h',yanchor='bottom',xanchor='center',y=-0.5,x=0.5),
    margin=MARGIN,
    font_size = font_size,
    yaxis_title="Peak (MW)",
    xaxis_title="Date",
    showlegend=True)

image

In your code with the x-axis setup, doesn’t the month name appear under the day when the month changes? The result is that the next month is recognized as having changed, but the x-axis splitting feature seems to work in the multi-index case and is not applicable in this case. Reference

@petemarvin, this solution should help you have the month name at the center

thank you for the idea, it think I already got it. Just need to add multiple index in go.scatter(x=[df_chart.month,df_chart.index])

Yes when I add the month, the month text would appear below the date, but what I want to achieve is the “Jun” text would be below the date 06 and the “May” text would be below around the date “21”

The only way left is to make your own scale. There may be several ways to do this, but you can create a list of day and month strings in the date string data of the data frame. Leave only the month name in the center position in the month list. Rejoin it with the list of days and a line break tag. To apply this, graph the x-axis of the original graph with integer indices and then update the tick marks.

ticks_day = [ x.strftime('%d-%b').split('-')[0] for x in df.index]
ticks_month = [ x.strftime('%d-%b').split('-')[1] for x in df.index]
may = ticks_month.count('May')
jun = ticks_month.count('Jun')
import math
new_month = [ t if i in [math.floor(may/2), may+math.floor(jun/2)] else '' for i,t in enumerate(ticks_month)]
new_ticks = [d+'<br>'+m for d,m in zip(ticks_day, new_month)]

fig.add_trace(go.Scatter(
    mode='markers+lines',
    x=np.arange(len(df)), #df.index,
    y=df['Close']
))

fig.update_xaxes(tickvals=np.arange(len(df)),ticktext=new_ticks)