I'm implementing a time schedule associated with business hour (8am to 5pm) using pd.offsets.CustomBusinessHour and attempting to plot the gantt chart or horizonal bar chart using matplotlib. At this point, I want to cut off the interval between x-axis ticks out of business hour which is unnecessary. It seems like breaking hours exist between 5pm of d-day and 8am of d+1 day
I searched parameter configuration of BusinessHour method, way of tick setting using keyword 'interval', 'spacing', however I couldn't find appropriate solution. I considered other plotting approaches using matplotlib.dates module but the result was in vain.
And this is my python code.
import pandas as pd
from datetime import datetime, date, timedelta, time
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.dates as mdates
num = 6
start_time = datetime(2021, 7, 7, 13, 5, 16, 268902)
int_to_time = pd.offsets.CustomBusinessHour(start="08:00", end="17:00", weekmask="1111111")
duration = num * int_to_time
horizon = [start_time + (i+1) * int_to_time for i in range(num+1)]
horizon = [i.replace(microsecond=0) for i in horizon]
fig, gnt = plt.subplots(figsize=(12,3))
gnt.barh(y=1, width=duration, left=start_time, color="cyan", height=0.2)
gnt.set_xticks(horizon)
gnt.set_xticklabels(horizon, rotation=90)
gnt.tick_params(bottom=False, labelbottom=False, top=True, labeltop=True)
plt.show()