I have a series of intraday measurements. measurements are only taken during daytime on weekdays. when I plot the data, pandas extends the xaxis over the full time horizont, so the plot shows data gaps
dfb.loc[:,("value", "exp_1")].plot()
I can tell pandas/matplotlib to ignore the index and the plot is fine, but I would like to present the dates on the x axis
dfb.loc[:,("value", "exp_1")].plot(ignore_index=True)
I also tried to define the xticks with my index, but that leads to teh first chart with a cluttered x axis description
dfb.loc[:,("value", "exp_1")].plot(xticks=dfb.index)
Is there a way to get a plot like the 2nd plot while keeping the dates?
EDIT: Here is a subset of the data and the plot
It looks a bit like a bug. You may also consider creating an issue on https://github.com/pydata/pandas/
When I tried it with a DatetimeIndex with frequency set to days or business days then the x axis isn't affected. But if the frequency is finer (e.g. hours, business hours), then the axis does get extended - exactly as in your case.
A workaround (not sure if the best possible) would be to convert the index of the data frame to strings. Either setting it directly:
df.index = df.index.astype('str')
or maybe better changing only for printing:
df.set_index(df.index.astype('str')).plot(rot=30)
The argument rot=30
is optional, but without it the labels get cluttered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With