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

Skip to content

FIX: colorbars with NoNorm #21872

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
Dec 8, 2021
Merged

FIX: colorbars with NoNorm #21872

merged 2 commits into from
Dec 8, 2021

Conversation

tacaswell
Copy link
Member

Closes #21870

This adds another special-case path for NoNorm and tweaks the contents of another.
These special-cases are required because NoNorm (like BoundaryNorm) has a
different return value than ever other Norm (it directly returns integers to
index into the LUT rather than [0, 1] that is later mapped into the LUT.

PR Summary

I added this as an SVG because getting the text right is a critical part of this and SVG will not suffer from our free-type issues.

(I went through a minor panic when I was not seeing ticklabels in the svg, but luckily that was a viewer (emacs) bug 😌 but I did have 15 minutes of thinking we had stopped outputting any text on SVGs! This may be (another) rsvg bug....)

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).

@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Dec 6, 2021
@tacaswell tacaswell added this to the v3.5.1 milestone Dec 6, 2021
@tacaswell tacaswell requested a review from jklymak December 6, 2021 05:17
@anntzer
Copy link
Contributor

anntzer commented Dec 6, 2021

Side tangent about svg: it may be worth switching at least some of the svg baseline outputs to use svg.fonttype = None which simply embeds text as text, gaining a lot on the svg sizes.

Comment on lines 931 to 932
fig.savefig('/tmp/wat.svg')
fig.savefig('/tmp/wat.png')
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
fig.savefig('/tmp/wat.svg')
fig.savefig('/tmp/wat.png')

Copy link
Member Author

Choose a reason for hiding this comment

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

🤦🏻 At least some of my even more frustrated debugging statements did not make it in!

@@ -839,7 +839,7 @@ def _get_ticker_locator_formatter(self):
# default locator:
nv = len(self._values)
base = 1 + int(nv / 10)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be moved up a level in the elif after BoundaryNorm? It seems out of place here...

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed.

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.

Added a few suggestions.

Part of my problem with these changes is that they were not exercised with tests and they did not have any comments, so it was pretty hard to know to check the specific cases. I think adding more comments in here will help in the future.

I'd need to think if there is more we can do on the Norm itself to inform the colorbar of how to set locators and ticks. I think we do that now with scales on the norm, so maybe BoundaryNorm and NoNorm can get scales.

tacaswell and others added 2 commits December 6, 2021 14:38
Closes matplotlib#21870

This adds another special-case path for NoNorm and tweaks the contents of another.
These special-cases are required because NoNorm (like BoundaryNorm) has a
different return value than ever other Norm (it directly returns integers to
index into the LUT rather than [0, 1] that is later mapped into the LUT.

Co-authored-by: Jody Klymak <[email protected]>
@tacaswell
Copy link
Member Author

I'd need to think if there is more we can do on the Norm itself to inform the colorbar of how to set locators and ticks. I think we do that now with scales on the norm, so maybe BoundaryNorm and NoNorm can get scales.

I agree, but not as a 3.5.1 patch.

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.

Thanks for chasing this down and fixing it, and apologies for breaking it in the first place!

@dstansby dstansby merged commit 57dc5f7 into matplotlib:main Dec 8, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Dec 8, 2021
dstansby added a commit that referenced this pull request Dec 8, 2021
…872-on-v3.5.x

Backport PR #21872 on branch v3.5.x (FIX: colorbars with NoNorm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: color/colorbar
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Colormap + NoNorm only plots one color under matplotlib 3.5.0
4 participants