0

Yo ! First of all thanks for your help. I know there are some similar topics but I want to understand and get an explaination please. Trying to plot stock prices evolution , I used this code:

import pandas_datareader as web
import matplotlib.pyplot as plt
import datetime as dt

tickers = ["AAPL", "MSFT", "AMZN"]
start_date = dt.datetime(2021,1,1)
end_date = dt.datetime(2021,2,10)
prices = web.get_data_yahoo(tickers,
    start = start_date,
    end = end_date)
prices["Adj Close"].plot()
plt.show()

I don't understand why when I plot the year part (x axis) gives something like 3990-01-05 ,etc.

Thanks for your help.

JaNa

MinatoDBO
  • 45
  • 1
  • 7
  • 1
    Thanks for the copy-pastable code sample. I tried running it and [it looks fine to me](https://i.stack.imgur.com/OKERZ.png), no problem with the dates. I am using matplotlib 3.3.2. Maybe the [epoch](https://matplotlib.org/api/dates_api.html#matplotlib.dates.set_epoch) has been changed somehow, you can check it with `plt.rcParams['date.epoch']`. – Patrick FitzGerald Feb 11 '21 at 10:04
  • It seems you want to change the x-tick label format using `DateFormatter` (many examples on SO, [see for instance here](https://stackoverflow.com/a/65343940/8881141) although it is not mad clear into what format you want to change it. – Mr. T Feb 11 '21 at 10:31
  • Mr.T I want to get something like YYYY MM DD . Using the command plt.rcParams I got 1970-01-01T00:00:00 + a message "The epoch2num function was deprecated in Matplotlib 3.3 and will be removed two minor releases later. base = dates.epoch2num(dt.asi8 / 1.0e9)". How can I fix it please ? thanks – MinatoDBO Feb 20 '21 at 11:35

0 Answers0