Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FIX: colorbar with boundary norm, proportional, extend#20987

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

jklymak
Copy link
Member

PR Summary

Colorbars with a Boundary norm and extend != 'none' were not working because the normalization included the extend boundaries, which are very very big. Normalizing with just the inside boundaries is the right thing to do.

Added an image test because I don't really know how to test this without, and this functionality is not well-tested elsewhere.

Closes#20963

PR Checklist

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (runflake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • Conforms to Matplotlib style conventions (installflake8-docstrings and runflake8 --docstring-convention=all).
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).

Copy link
Contributor

@greglucasgreglucas left a comment

Choose a reason for hiding this comment

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

Looks good to me, and I think the image test makes sense.

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

Optional comments.

Comment on lines 844 to 846
cmap = mcolors.ListedColormap(['r', 'g', 'white', 'g', 'r'])
cmap.set_under('yellow')
cmap.set_over('cyan')
Copy link
Member

Choose a reason for hiding this comment

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

Optional, but the test is stonger if you break the symmetry of the colors. With the symmetry, you cannot check the sign.

Suggested change
cmap=mcolors.ListedColormap(['r','g','white','g','r'])
cmap.set_under('yellow')
cmap.set_over('cyan')
cmap=mcolors.ListedColormap(
['0.3','0.5','white','lightblue','steelblue'])
cmap.set_under('darkred')
cmap.set_over('crimson')

grafik

Also, I've chosen colors that hurt the eye a little less 😄

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

sure

style='mpl20')
def test_proportional_colorbars():

x = y = np.arange(-3.0, 3.01, 0.025)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
x=y=np.arange(-3.0,3.01,0.025)
x=y=np.linspace(-3,3,241)

np.arange with non-integer step is generally not recommended

https://numpy.org/doc/stable/reference/generated/numpy.arange.html:

When using a non-integer step, such as 0.1, the results will often not be consistent. It is better to use numpy.linspace for these cases.

While it doesn't matter for the test, let's set a good example.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I guess I don't understand this advice.Very often one wants to specify dx instead of N. Sure you can compute one from the other, but I don't see why one would be more consistent than the other.

Copy link
Member

@timhoffmtimhoffmSep 4, 2021
edited
Loading

Choose a reason for hiding this comment

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

Since you have limited numeric precision, the results are only approximately the same. Forarange you often don't get expected "exact" numbers. e.g. the middle value is 0 withlinspace but 1.06e-14 witharange. Additionally, the "endpoint not included" feature makes sense for indices, but is a somewhat awkard API for (float)numeric sequences. And in conjunction with the numeric jitter, this can have surprising effects; e.g.https://stackoverflow.com/questions/10011302/python-numpy-arange-unexpected-results.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Sure, that's just floating point arithmetic. I'm not convinced that makes arange bad style or "inconsistent"

Copy link
Member

@timhoffmtimhoffmSep 5, 2021
edited
Loading

Choose a reason for hiding this comment

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

Well, "inconsistent" is numpy's description. That may not be the best term.

However, that the endpoint and number of points depend on small numeric effectsis highly problematic. Practically, you don't know what you will get if endpoint is start + N times interval.

Anyway, I'm not going to argue more about this within a test.

@jklymakjklymakforce-pushed thefix-colorbar-boundary-extend branch fromacb101e tof41edb6CompareSeptember 4, 2021 08:41
@timhoffmtimhoffm merged commit8ce14fb intomatplotlib:masterSep 5, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestSep 5, 2021
@lumberbot-app
Copy link

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.4.x$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 8ce14fb60d9441ce3fb92e6e59b4aa3146aca6c1
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #20987: FIX: colorbar with boundary norm, proportional, extend'
  1. Push to a named branch :
git push YOURFORK v3.4.x:auto-backport-of-pr-20987-on-v3.4.x
  1. Create a PR against branch v3.4.x, I would have named this PR:

"Backport PR#20987 on branch v3.4.x (FIX: colorbar with boundary norm, proportional, extend)"

And apply the correct labels and milestones.

Congratulation you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to removeStill Needs Manual Backport label once the PR gets merged.

If these instruction are inaccurate, feel free tosuggest an improvement.

dstansby added a commit that referenced this pull requestSep 5, 2021
…987-on-v3.5.xBackport PR#20987 on branch v3.5.x (FIX: colorbar with boundary norm, proportional, extend)
@QuLogicQuLogic modified the milestones:v3.4.4,v3.5.0Sep 7, 2021
@QuLogic
Copy link
Member

It never worked, so I don't think we should go through the trouble of figuring out the backport.

@jklymak
Copy link
MemberAuthor

Agreed. The back port would be really hard given the changes to colorbar in 3.5

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm approved these changes

@greglucasgreglucasgreglucas approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.5.0
Development

Successfully merging this pull request may close these issues.

[Bug]: broken 'proportional' colorbar when using contourf+cmap+norm+extend
4 participants
@jklymak@QuLogic@timhoffm@greglucas

[8]ページ先頭

©2009-2025 Movatter.jp