Skip to content

df.plot() with kind='scatter' and datetime on x axis bug #30391

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

Closed
Sbrowneo opened this issue Dec 21, 2019 · 4 comments · Fixed by #30434
Closed

df.plot() with kind='scatter' and datetime on x axis bug #30391

Sbrowneo opened this issue Dec 21, 2019 · 4 comments · Fixed by #30434
Assignees
Labels
Milestone

Comments

@Sbrowneo
Copy link

I noticed while helping a student that there's a bug when calling a scatter plot as a method on a DataFrame. Regardless of what the index is or what the x argument is, it appears that pandas makes the x argument into the index, and then searches for the x in the columns, where it no longer exists. When calling the same directly through matplotlib as plt.scatter, it worked properly.

Pandas_Error_scatter

@jbrockmendel jbrockmendel added the Visualization plotting label Dec 22, 2019
@MarcoGorelli
Copy link
Member

Any chance you could post a copy-and-pasteable code example so we more easily reproduce the issue?

@Sbrowneo
Copy link
Author

Sorry, I was helping a student whose code wasn't working, I don't have the original code myself. However I tried to recreate the error myself and I'm now getting something different:

dates=pd.date_range(start=datetime.date(2019,1,1),periods=12,freq='W')
vals=np.random.normal(0,1,len(dates))
df=pd.DataFrame({'dates':dates,'vals':vals})
df.plot(x='dates',y='vals',kind='scatter')

This gives me a different error:

image

However,

plt.scatter(x=df['dates'],y=df['vals'])

does work, so I'm not sure if this is a bug or if scatter is supposed to throw an error when datetime objects are on the X axis. I'm also not sure why the error I'm getting is different from my student's.

@MarcoGorelli
Copy link
Member

OK, thanks! I don't know about your student's error, but your one was already opened in #18755

@charlesdong1991
Copy link
Member

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants