Skip to content

Allow list-like for y in DataFrame.plot. #19699

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
TomAugspurger opened this issue Feb 14, 2018 · 6 comments · Fixed by #20000
Closed

Allow list-like for y in DataFrame.plot. #19699

TomAugspurger opened this issue Feb 14, 2018 · 6 comments · Fixed by #20000
Labels
API Design Regression Functionality that used to work in a prior pandas version Visualization plotting
Milestone

Comments

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Feb 14, 2018

In pandas 0.22 and earlier, we passing multiple values for y worked by accident. The code clearly assumed that y was a scalar, but things usually worked, perhaps with an incidental warning:

In [12]: df = pd.DataFrame(np.random.uniform(size=(10, 2)), columns=['a', 'b'])

In [15]: df.plot(x='c', y=['a', 'b'])
/Users/taugspurger/miniconda3/envs/pandas-0.21.0/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label
Out[15]: <matplotlib.axes._subplots.AxesSubplot at 0x10f83b198>

On master, this will currently raise. I think that we should explicitly support list-likes for y.

Tagging for 0.23 since I think this should be a blocker.

xref #18695 where we made the change.

@TomAugspurger TomAugspurger added Visualization plotting Regression Functionality that used to work in a prior pandas version API Design Difficulty Intermediate labels Feb 14, 2018
@TomAugspurger TomAugspurger added this to the 0.23.0 milestone Feb 14, 2018
@TomAugspurger
Copy link
Contributor Author

@masongallo do you have any time / interest to work on this?

@masongallo
Copy link
Contributor

@TomAugspurger yes I would be happy to help once I get some time, hopefully later this week.

Can you give a bit more details on what you would expect to return in your example above (or a similar example where the user supplies multiple y columns)?

@TomAugspurger
Copy link
Contributor Author

TomAugspurger commented Feb 20, 2018

Thanks! I think it should be equivalent to df.set_index('c')[['a', 'b']].plot(). So multiple lines, each plotted against the x.

@masongallo
Copy link
Contributor

Gotcha - this only makes sense if a and b are on the "same" scale right?

The plot method has a secondary_y arg but I'm not sure it makes sense to use in a general case like this.

@TomAugspurger
Copy link
Contributor Author

TomAugspurger commented Feb 26, 2018 via email

@masongallo
Copy link
Contributor

Accepting a list-like for y would allow for an arbitrary number of lines all with
the same y axis.

This makes sense to me & I think the usecase is clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Regression Functionality that used to work in a prior pandas version Visualization plotting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants