0

I would like to plot the following data

>>> AllSummary
      upload_date  Gross Loan Amount  NewPerfColumn
    0  2018-02-19       1.532472e+11   2.624765e+08
    1  2018-03-01       1.475863e+11   1.361267e+08
    2  2018-03-12       1.376221e+11   1.133450e+08

As shown below, the column "upload_date" is definitely recognized as a date

AllSummary.dtypes
upload_date          datetime64[ns]
Gross Loan Amount           float64
NewPerfColumn               float64
dtype: object

but when i plot the data it shows x-xis as a number (not as date): the code is below

x=AllSummary['upload_date']
y1 =AllSummary['Gross Loan Amount']
y2 =AllSummary['NewPerfColumn']
fig, ax1 = plt.subplots()

ax2 = ax1.twinx()
ax1.plot(x, y1, 'g-')
ax2.plot(x, y2, 'b-')

ax1.set_xlabel('Date')
ax1.set_ylabel('Gross Loan Amount', color='g')
ax2.set_ylabel('Performance', color='b')

plt.show()

why is it the case?

SBad
  • 1,245
  • 5
  • 23
  • 36
  • You may try `ax1.plot_date`. Otherwise you would need to use a `matplotlib.dates` formatter to select the format you want to show, e.g. `plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y'))`, see [this question](https://stackoverflow.com/questions/9627686/plotting-dates-on-the-x-axis-with-pythons-matplotlib). In case this is still not doing what you want, please provide a [mcve] and clearly state which versions of the libraries (matplotlib, pandas) you are using. – ImportanceOfBeingErnest Mar 23 '18 at 12:29
  • can you please be more clear when you say use ax1.plot_date . how can it be used in the example above? – SBad Mar 23 '18 at 13:02
  • 1
    Replace the line `ax1.plot(x, y1, 'g-')` by `ax1.plot_date(x, y1, 'g-')`. – ImportanceOfBeingErnest Mar 23 '18 at 13:02
  • it is not working i would need to explore the second option – SBad Mar 23 '18 at 13:09

0 Answers0