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

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

Closed
TomAugspurger opened this Issue Feb 14, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@TomAugspurger
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

This comment has been minimized.

Contributor

TomAugspurger commented Feb 20, 2018

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

@MasonGallo

This comment has been minimized.

Contributor

MasonGallo commented Feb 20, 2018

@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

This comment has been minimized.

Contributor

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

This comment has been minimized.

Contributor

MasonGallo commented Feb 26, 2018

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

This comment has been minimized.

Contributor

TomAugspurger commented Feb 26, 2018

@MasonGallo

This comment has been minimized.

Contributor

MasonGallo commented Feb 26, 2018

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