Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix issue with colorbar extend and drawedges #22865

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 2 commits into from
Jun 15, 2022
Merged

Fix issue with colorbar extend and drawedges #22865

merged 2 commits into from
Jun 15, 2022

Conversation

oscargus
Copy link
Member

@oscargus oscargus commented Apr 20, 2022

PR Summary

Closes #22864

Maybe the test can be simplified/written in a better way?

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Is this new behaviour? Or did it get broken in the colorbar overhaul?

@oscargus
Copy link
Member Author

oscargus commented Apr 20, 2022

Is this new behaviour? Or did it get broken in the colorbar overhaul?

No idea. Seems to make sense to have it the "new" way, but maybe I miss something. Should be pretty straightforward to add a keyword argument to enable/disable this if required.

Edit: seems like new behavior, at least compared to the last time someone touched those lines. #20054

Edit 2: seems like the concept of removing the first and last element was introduced in 4d1107c (see the _edges method, later simplified and inlined). @efiring close to 16 years ago, but do you remember any design decision here?

So probably we would like to introduce a keyword argument for this? Still, I tend to think that the separators are expected when extending, so maybe it should be on by default?

I also assume that a release note should be included then?

@oscargus
Copy link
Member Author

Thinking a bit more about it, it seems like one would like to have the option to disable this. For example if the extend part has the same color as the adjacent block. A good name for the keyword argument?

@oscargus oscargus marked this pull request as draft April 22, 2022 15:00
@timhoffm
Copy link
Member

timhoffm commented Apr 22, 2022

IMHO it could be sufficient to draw a line if the extent color (i.e. over/under) is different and not draw a line if the color is the same. That should almost always be the desired behavior. We should not unnecessarily bloat our API with options that nobody needs. We can always add a kwarg later if needed.

@oscargus
Copy link
Member Author

IMHO it could be sufficient to draw a line if the extent color

I've also come to that conclusion after looking at more examples.

@jklymak
Copy link
Member

jklymak commented Apr 22, 2022

Further, I'm not sure this is needed at all. I think this is new behaviour, and it may break as many people as it helps. If the extend color is the same, it is probably unwanted to have a break; if the extend color is different, there is a clear visual break anyways. So I'm not sure that there is a lot of semantic aid this is giving that's worth changing behaviour? I'm also against all the special flags and duck typing and checks we have for colorbar - its API has really gotten out of hand over the years.

@timhoffm
Copy link
Member

@jklymak I'm unclear whether you agree with my proposal (not configurable but line/no line depends on the colors) or whether you argue for always no line. I agree neither is a question of semantics, but I think my proposal is better from an aesthetic perspective.

@jklymak
Copy link
Member

jklymak commented Apr 22, 2022

I wouldn't add the line...

@efiring
Copy link
Member

efiring commented Apr 22, 2022

I never use drawedges, and I don't know what the old behavior was (but see below). But logically, I think that if drawedges is requested, then there should be a line at the base of the triangle, regardless of whether the color changes. It's a boundary with a logical meaning, no different from any of the other boundaries, which also might or might not coincide with a color change. The user has said "draw lines at boundaries", so just do it. I strongly oppose putting in color-checking logic or a kwarg. I'm not strongly opposed to rejecting the change entirely and saying "we will leave this minor inconsistency in place", but I think #22864 is a valid issue.

History: quickly looking at 4d1107c, I think this is consistent with drawing edges at the triangle bases. The _edges method is omitting the ends of the bar, which would be the triangle tips when there are extensions, or the actual colorbar ends when there are no extensions. The entire colorbar was drawn as a single pcolormesh; the extensions were not tacked on separately. In other words, I think that the current behavior is new, in which case the current PR is fixing a regression.

@jklymak
Copy link
Member

jklymak commented Apr 22, 2022

OK agreed, this was a regression - if you checkout 3.4.2 then you get the extra lines. So a simple fix as proposed here should be correct.

@oscargus
Copy link
Member Author

Thanks for the feedback!

Will update the PR to check if the extend parts have different or the same color as well.

@efiring
Copy link
Member

efiring commented Apr 23, 2022

@oscargus, to be sure it is clear: There is no point in checking whether the colors are the same or not. The PR will be ready to go with only the code clarification suggested by @timhoffm.

@jklymak
Copy link
Member

jklymak commented May 17, 2022

This is ready to merge when you make the change above, right?

@oscargus
Copy link
Member Author

Since I messed up and pushed this to the base repo rather than my own and I then changed things to avoid that, I am not really sure how to edit this properly. Hence, I would like to ask for a squash merge.

(Also, the alpha test promised in #23260 (comment) is ideally postponed.)

@oscargus oscargus marked this pull request as ready for review June 14, 2022 08:08
@oscargus
Copy link
Member Author

I think the doc build failure is because I pushing this to the main repo. Especially since I didn't change anything related to the docs...

@timhoffm timhoffm added this to the v3.6.0 milestone Jun 15, 2022
@timhoffm timhoffm merged commit 00cdf28 into main Jun 15, 2022
@timhoffm timhoffm deleted the drawedgesextend branch June 15, 2022 16:17
@QuLogic
Copy link
Member

QuLogic commented Jun 15, 2022

This was a regression from 3.4.2 according to @jklymak, so it should be backported to v3.5.x.

@meeseeksdev backport to v3.5.x

@QuLogic QuLogic modified the milestones: v3.6.0, v3.5.3 Jun 15, 2022
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jun 15, 2022
QuLogic pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jun 21, 2022
timhoffm added a commit that referenced this pull request Jun 21, 2022
…865-on-v3.5.x

Backport PR #22865 on branch v3.5.x (Fix issue with colorbar extend and drawedges)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Colorbar with drawedges=True and extend='both' does not draw edges at extremities
5 participants