✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Remove gaps from time-series/OHLC plot

How can I remove breaks/gaps in plots with dates?

Take the following example:

import pandas as pd
import numpy as np
import plotly.graph_objects as go

np.random.seed(404)

times = [pd.Timestamp.now() + pd.Timedelta(i*4, unit='H') for i in range(50)]
vals = 100*np.cumprod(1 + np.random.normal(scale=0.1, size=50))

df = pd.DataFrame({'times': times, 'vals': vals})
df.query("times < '2020-06-27' | times > '2020-06-28 23:00'", inplace=True)

fig = go.FigureWidget()
fig.add_scatter(x=df['times'], y=df['vals'])
fig

I want June 26 to and the first 23 hours of June 28 removed from the plot.
I actually need this for a candlestick plot, but I assume the procedure will be similar.

I saw that there was an issue about this:

I tried @etienne’s example there, by adding:
xaxis_breaks = dict(values=['2020-06-27', '2020-06-28'])
to the layout, but it didn’t work.