Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting incorrectly reversed when using dates as x-axis #3601

Closed
rhstanton opened this issue May 14, 2013 · 5 comments

Comments

@rhstanton
Copy link

commented May 14, 2013

Sometimes I have to read in spreadsheets containing data with the most
recent observations first. If I try to plot these without re-sorting
first, the graph appears backwards. The dates on the x-axis are in
ascending order, but the data are plotted from left to right in the same
order they appeared in the spreadsheet. Since there's no warning that the
labels on the axis don't correspond to the data being plotted, this can
cause some embarrassment! This only happens when I use timestamps; dates
as integers work fine.

For example, this works fine (dates reversed, stored as int)

df2 = DataFrame({'Date' : [1998, 1997, 1996], 'Data' : [9, 8,
7]}).set_index('Date')
df2.plot()

This doesn't (same data set, but dates stored as timestamp instead):

from dateutil import parser
df = DataFrame({'Date' : ['1998-01-01', '1997-01-01', '1996-01-01'],
'Data' : [9, 8, 7]})
df.index = df.Date.map(parser.parse)
del df['Date']
df.plot()

I can get around the problem by sorting the data set before plotting, but
I don't always remember, and it definitely seems odd that the graph ends
up displaying something that is not actually in the original data set...

@dieterv77

This comment has been minimized.

Copy link
Contributor

commented May 18, 2013

I think this should be fixed with 3b37088

@rhstanton

This comment has been minimized.

Copy link
Author

commented May 18, 2013

The graph in my example now plots correctly. Thanks!

I notice that the format of the x-axis labels has changed too. Was that deliberate?

From: dieterv77 [mailto:notifications@github.com]
Sent: Friday, May 17, 2013 5:00 PM
To: pydata/pandas
Cc: Richard Stanton
Subject: Re: [pandas] Plotting incorrectly reversed when using dates as x-axis (#3601)

I think this should be fixed with 3b370883b37088


Reply to this email directly or view it on GitHubhttps://github.com//issues/3601#issuecomment-18091682.

@jreback

This comment has been minimized.

Copy link
Contributor

commented May 19, 2013

@dieterv77 @rhstanton close this?

@rhstanton

This comment has been minimized.

Copy link
Author

commented May 19, 2013

Works fine on my example. Many thanks.

From: jreback [mailto:notifications@github.com]
Sent: Sunday, May 19, 2013 9:52 AM
To: pydata/pandas
Cc: Richard Stanton
Subject: Re: [pandas] Plotting incorrectly reversed when using dates as x-axis (#3601)

@dieterv77https://github.com/dieterv77 @rhstantonhttps://github.com/rhstanton close this?


Reply to this email directly or view it on GitHubhttps://github.com//issues/3601#issuecomment-18120701.

@jreback

This comment has been minimized.

Copy link
Contributor

commented May 19, 2013

closed via 3b37088

@jreback jreback closed this May 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.