Skip to content
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

FIX: fix colorbars with no scales #20327

Merged
merged 1 commit into from Jun 10, 2021

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented May 28, 2021

PR Summary

Closes #20324

The colorbar re-write #20054, needs a scale for the colorbar. Which worked great for most of our Norms because they are all created from a scale now:

def _make_norm_from_scale(scale_cls, base_norm_cls=None, *, init=None):

However, astropy did not derive their norms from a scale, so they had a failure (which I hope this fixes). astropy/astropy#11800

We also had norms like TwoSlopeNorm that do not derive from a scale, though they probably should/could.

Here the proposal is that if there is no scale on the norm, the scale is a function scale with the forward and inverse from the norm. This works fine for TwoSlopeNorm (ahem, after we define the inverse for it, which really should have been done when it went in; that took a bit of work to realize).

PR Checklist

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

@jklymak jklymak added this to the v3.5.0 milestone May 28, 2021
@jklymak jklymak added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label May 28, 2021
@jklymak jklymak force-pushed the fix-colorbars-with-no-scale branch 2 times, most recently from 2177d8c to 52a6aa8 Compare May 28, 2021 22:42
@@ -1152,7 +1152,7 @@ def __init__(self, vmin=None, vmax=None, clip=False):
self.vmin = _sanitize_extrema(vmin)
self.vmax = _sanitize_extrema(vmax)
self.clip = clip
self._scale = scale.LinearScale(axis=None)
self._scale = None # will default to LinearScale for colorbar
Copy link
Member Author

Choose a reason for hiding this comment

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

Note downstream libraries will likely derive from Normalize, so scale should be None so their norm gets used...

Copy link
Member Author

Choose a reason for hiding this comment

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

@dstansby can you see if this version works?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, seems to work well with this version.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any chance of a formal review?

@jklymak jklymak force-pushed the fix-colorbars-with-no-scale branch from 7867fc3 to 1e8658d Compare May 29, 2021 20:55
lib/matplotlib/colorbar.py Outdated Show resolved Hide resolved
@image_comparison(['colorbar_twoslope.png'], remove_text=True,
style='mpl20')
def test_twoslope_colorbar():
# Note that the first tick = 20, and should be in the middle
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding the ticklabels to the image would be helpful 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.

Yeah, I agree, but we really try to avoid labels, because they cause image comparison problems when the font library changes...

lib/matplotlib/colorbar.py Outdated Show resolved Hide resolved
@jklymak jklymak mentioned this pull request Jun 3, 2021
7 tasks
@jklymak jklymak force-pushed the fix-colorbars-with-no-scale branch from 87b8ae7 to d1c5a6a Compare June 3, 2021 14:34
@anntzer anntzer merged commit 29da23a into matplotlib:master Jun 10, 2021
@jklymak jklymak deleted the fix-colorbars-with-no-scale branch June 10, 2021 20:09
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.

New colorbar doesn't handle norms without a scale properly...
5 participants