I want to plot a pandas series which index is incountinuous DatatimeIndex. My code is as follows:
import matplotlib.dates as mdates
index = pd.DatetimeIndex(['2000-01-01 00:00:00', '2000-01-01 00:01:00',
'2000-01-01 00:02:00', '2000-01-01 00:03:00',
'2000-01-01 00:07:00',
'2000-01-01 00:08:00'],
dtype='datetime64[ns]')
df = pd.Series(range(6), index=index)
print(df)
plt.plot(df.index, df.values)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%M"))
plt.show()
The output is:
But the result is not what I really want, because 2000-01-01 00:04:00 is also plotted on the image. The desired outcome is that on the x-axis 03:00 is next to 07:00 and the image should be a straight line. Hope for your great idea.