1

I have a bunch of dates in the form MM / DD / YYYY. I use a parser to get them into something that looks like datetime.datetime(YYYY, MM, DD, 0, 0) .

I have data corresponding to each date in an array y and would like to plot the two arrays against one another. Using matplotlib.dates.date2num I plot them as

x= matplotlib.dates.date2num(dates)

plot_date(dates,y)

When I do this, I get the following plot

enter image description here

Where as I would prefer something that looks like a time series.

How can I fix this

1 Answer 1

2

Presumably the dates and data that you're reading in are not in time order, in which case you'll need to sort them both before they're passed to plot_date():

s = np.argsort(dates)
plot_date(dates[s],y[s])

This should work whether you sort on the list/array of datetime instances (your dates) or their numerical equivalents (your x).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.