Skip to content

Update handling of sequence labels for plot#27767

Merged
QuLogic merged 1 commit into
matplotlib:mainfrom
rcomer:plot-single-legend
Feb 15, 2024
Merged

Update handling of sequence labels for plot#27767
QuLogic merged 1 commit into
matplotlib:mainfrom
rcomer:plot-single-legend

Conversation

@rcomer

@rcomer rcomer commented Feb 10, 2024

Copy link
Copy Markdown
Member

PR summary

Closes #27762.

  • plot(x, y, label=['foo']) where y is 1D now results in the legend label "foo" instead of "['foo']" (immediate change).
  • plot(x, y, label=sequence) where y is 1D and sequence is not of length 1 is deprecated to error in future.

PR checklist

@rcomer rcomer added API: changes Changes to the public API, typically requiring deprecation. topic: legend topic: plotting methods labels Feb 10, 2024
@rcomer rcomer added this to the v3.9.0 milestone Feb 10, 2024
@rcomer

This comment was marked as outdated.

@rcomer rcomer marked this pull request as draft February 10, 2024 15:21
@rcomer rcomer force-pushed the plot-single-legend branch from 2368337 to 2d610df Compare February 10, 2024 18:28
@rcomer

This comment was marked as outdated.

@rcomer rcomer marked this pull request as ready for review February 10, 2024 18:51
@rcomer rcomer force-pushed the plot-single-legend branch from 2d610df to be1ebc2 Compare February 10, 2024 19:18
timhoffm

This comment was marked as outdated.

@rcomer

This comment was marked as outdated.

@rcomer rcomer force-pushed the plot-single-legend branch from 5a029d8 to af43359 Compare February 11, 2024 08:17
@timhoffm

This comment was marked as outdated.

@rcomer

This comment was marked as outdated.

@timhoffm

This comment was marked as outdated.

@timhoffm

Copy link
Copy Markdown
Member

@rcomer I've introduced #27780, which should resolve the boxplot issues you've had with this PR. I suggest to wait until that gets merged, then rebase on it and remove all the boxplot specifics here.

@rcomer

rcomer commented Feb 15, 2024

Copy link
Copy Markdown
Member Author

Hid a bunch of comments because they discuss issues with boxplot that are now being handled elsewhere. This change no longer touches boxplot.

Comment thread lib/matplotlib/axes/_base.py Outdated
if cbook.is_scalar_or_string(label):
labels = [label] * n_datasets
else:
if len(label) != n_datasets:

@timhoffm timhoffm Feb 15, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional but inverting the if branches is more readable:

Suggested change
if len(label) != n_datasets:
if len(label) == n_datasets:
  • you remove the negation in the condition
  • And the short and good-case branch comes first

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm a little sleepy but I think this if doesn't have an else.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, I think I get it. I can have a look this evening (on the wrong computer at the moment).

@rcomer rcomer force-pushed the plot-single-legend branch from a1ef60c to ffc7ab0 Compare February 15, 2024 18:49
@ksunden

ksunden commented Feb 15, 2024

Copy link
Copy Markdown
Member

Anyone can merge on green CI

@QuLogic QuLogic merged commit af80c90 into matplotlib:main Feb 15, 2024
@rcomer rcomer deleted the plot-single-legend branch February 15, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API: changes Changes to the public API, typically requiring deprecation. topic: axes topic: plotting methods

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Inconsistent treatment of list of labels in plot when the input is a dataframe

4 participants