Anudocs
Anudocs

Reputation: 686

Plotting dates on x axis in matplotlib

I have a list of dates:

x = ['20200116, '20200117']

which i want to plot on x-axis. I used below code for formatting the list:

x = (datetime.datetime.strptime(date, '%Y%m%d').strftime('%m/%d/%Y') for date in x)

Expected output : a list with dates in '%m/%d/%Y' format but it returns an object. What am i doing wrong here?

Upvotes: 0

Views: 41

Answers (1)

funnydman
funnydman

Reputation: 11376

Here x variable is a generator object, either use list(x) or [...] instead of (...).

Upvotes: 1

Related Questions