Time series plotting issue

41 views Asked by At

I'm having a problem plotting time series using matplotlib.pyplot. This is my DataFrame:

    saledate    MA
0   2007-09-30  441854
1   2007-12-31  441854
2   2008-03-31  441854
3   2008-06-30  441854
4   2008-09-30  451583

The Dtypes:

Data columns (total 2 columns):
 #   Column    Non-Null Count  Dtype         
---  ------    --------------  -----         
 0   saledate  347 non-null    datetime64[ns]
 1   MA        347 non-null    int64         
dtypes: datetime64[ns](1), int64(1)

I used the code below to plot the chart, however, it's not like what I expect.

plt.plot(df['saledate'], df['MA'])
plt.show()

This is the output from my code: The output from the blockcode

I also tried changing the index to the 'saledate', then changed the dataframe to a series to plot but I still encountered the same problem.

This is an example of my expected output: Expected output

Could you please help me with this problem?

0

There are 0 answers