I don't understand how I use and format a timedelta
axis properly in matplotlib.
For example, for the following code
import pandas as pd # for plot generation
import matplotlib.pyplot as plt
index = pd.timedelta_range(timedelta(days=0), timedelta(days=30), freq='H', closed='right')
s = pd.Series(range(0, 720), index=index)
fig, ax = plt.subplots(figsize=(5, 5))
s.plot(ax=ax)
I get the plot
But obviously, the tick positions and the labels are useless and not in a meaningful distance (e.g., one day). I could not find in documentation how to deal with timedelta
. Related questions ([1] or [2]) describe how to format the string but don't seem to handle the ticks layout.
How can I specify the ticks and the labels? For example, major ticks to days, minor ticks to hours with a proper label?
I also wonder if there is a simple, clean, pythonic solution. I mean timedelta in plots isn't that rare, is it? :)