I am using matplotlib to plot a dataframe.
However, I cannot work out how to plot the x-axis correctly as dates, when the x-axis is the df.index dates.
The output below x-axis dates are wrong.
import pandas as pd
import matplotlib.pyplot as plt
dttm = ["2021-01-01", "2021-01-02", "2021-01-03"]
dttm = pd.to_datetime(dttm)
data = [10, 20, 30]
DF = pd.DataFrame()
DF['value'] = data
DF = DF.set_index(dttm)
print(DF)
plt.plot(DF)
plt.gcf().autofmt_xdate()
plt.show()
df printed:
value
2021-01-01 10
2021-01-02 20
2021-01-03 30