How to prevent auto filled vacancy timestamp x labels in the plot

Hi,

I am working with a time series data (pd.Series) with DatetimeIndex as index.

It is worth noting that there are no data between the ["11:30:00", "13:00:00").

And the problem is when I trying to plot the time series data, it seems that it will automatically fill the vacancy timestamp in the plot, as shown below:

So I have to reset_index to a ordinal index to avoid that, but in this way, the timestamp info is missing too:

How can I prevent this auto filled timestamp when working with time series data with vacancies in DatetimeIndex ?

Thanks in advance!

It’s not clear what you’d like to have happen? If you have no data from 11:00 to 13:00 there is going to be a data gap if you plot with dates.

Thank you very much for the reply!

What I want to accomplish is the following result, still using the DatetimeIndex as x-ticks, but without the long horizontal line (or gap) between 11:30 to 13:00.

image

Is this possible by using DatetimeIndex as index? or I have to convert the DatetimeIndex to string before the plotting?

I would be nice if there are some reference docs and examples.

If you want the date to be on the xaxis (your index), and your data has gaps, then that is what Matplotlib/pandas will show. If you want sample number as your index, then switch to that, and you perhaps could label every 50th sample with a date if that is important. If you want to show the gap clearly, then you could make two subplots, and put the data from either side of the gap in each subplot.

What you are asking for is pretty non-standard, so you are going to have to do something special to make it work.

You may want to use something like this broken axis:
https://matplotlib.org/stable/gallery/subplots_axes_and_figures/broken_axis.html