Skip to content

BUG: fix Series.plot label setting #10131

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

Merged
merged 1 commit into from
May 19, 2015

Conversation

TomAugspurger
Copy link
Contributor

Closes #10119, a regression in 0.16.1

Basically Series.plot(label='foo') isn't actually setting the label.

I want to look at one more thing. With this fix you'd need

s.plot(label='foo', legend=True

to get the legend to actually show up. I can't remember what the old behavior was. At least for seaborn, setting a label implies that the legend should be drawn (e.g. sns.kdeplot(s, label='foo'))

@jreback jreback added Visualization plotting Regression Functionality that used to work in a prior pandas version labels May 14, 2015
@jreback jreback added this to the 0.17.0 milestone May 14, 2015
@sinhrks
Copy link
Member

sinhrks commented May 14, 2015

I can't remember what the old behavior was.

Because of the default value of plot_series, no legend should appear otherwise specified in prior versions.

https://github.com/pydata/pandas/blob/master/pandas/tools/plotting.py#L2492

@TomAugspurger
Copy link
Contributor Author

That's what I thought. Ok, I suppose we'll keep it like that for now. So ts.plot(label='series') will attach the legend information, but not actually draw the legend.

s.name = 'NAME'
ax = s.plot(legend=True)
self._check_legend_labels(ax, labels=['NAME'])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add here a test for the case where the series has a name, but you provide a label (so add ´s.plot(label='LABEL', legend=True)´ and then check the legend label is LABEL and not NAME)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Updated.

@TomAugspurger
Copy link
Contributor Author

I think this is ready then. Will merge once Travis is green.

TomAugspurger pushed a commit that referenced this pull request May 19, 2015
BUG: fix Series.plot label setting
@TomAugspurger TomAugspurger merged commit 01a8b37 into pandas-dev:master May 19, 2015
@shoyer
Copy link
Member

shoyer commented May 19, 2015

Thanks @TomAugspurger !

@schmohlio
Copy link

@TomAugspurger Thanks, Tom.

I'm trying to tie back to my commit - #9574 . I don't have that .pop() in _compute_plot_data() within my commit. Was that added somewhere else? In fact I deleted a .pop() line in my commit.

@jorisvandenbossche
Copy link
Member

@schmohlio This specific line that @TomAugspurger changed in this PR was in any case not introduced by your PR (https://github.com/pydata/pandas/blame/95dc0506f1a9237b0a34a1d26eba1e1a8d357758/pandas/tools/plotting.py#L1001), so certainly not necessary a regression by your PR! (and anyway, who introduced it does not really matter, as it is reviewed by multiple people and we should improve the test suite to catch such things)
But it was a case we could have thought of to test as well .. (easy to say afterwards of course), we only tested dataframes and not series I think.

@schmohlio
Copy link

@jorisvandenbossche both thoughts makes a lot of sense. Just wanted to see if I could help at any point. Thanks again for you and your team's great work.

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

Successfully merging this pull request may close these issues.

Series.plot() ignores label keyword
6 participants