astropy: Stretched norm behaviour broken on development `Matplotlib`

Description

Using a stretch norm is different on the development version of Matplotlib. The issue (see below for an example) bisects to the following change in Matplotlib: https://github.com/matplotlib/matplotlib/commit/146856b03e85aa4b1becdd89fe1628f98fed2a05, part of https://github.com/matplotlib/matplotlib/pull/20054. It’s not clear to me whether this is something that needs to be fixed in Matplotlib, or something needs changing in astropy.

Steps to Reproduce

import matplotlib.pyplot as plt
import numpy as np

from astropy.visualization import ImageNormalize, AsinhStretch

fig, ax = plt.subplots(figsize=(6, 2))
data = np.atleast_2d(np.linspace(0, 0.9, 10))
# data == [[0.  0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]]
im = ax.imshow(data, norm=ImageNormalize(vmin=0, vmax=1, stretch=AsinhStretch()), cmap='prism')
fig.colorbar(im, orientation='horizontal')
plt.show()

Image before Matplotlib change:

before

Image after Matplotlib change:

after

Note how the colorbar is now stretched insetad of the ticks.

System Details

macOS-10.16-x86_64-i386-64bit Python 3.9.1 (default, Dec 11 2020, 06:28:49) [Clang 10.0.0 ] Numpy 1.19.3 astropy 4.3.dev1547+gb52c40715 Scipy 1.5.4 Matplotlib 3.4.2.post948+g08f4629d91

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (11 by maintainers)

Most upvoted comments

To fix there’s nothing to do on the astropy side, but if astropy tests against Matplotlib dev a test should probably be added so this kind of bug is caught in the future - initially I found the bug in sunpy tests, and then isolated it to astropy.

@dstansby or @pllim 95% sure matplotlib/matplotlib#20327 will work with your Norm the way you expect. Sorry for the bother, and very very much appreciate you testing our dev branch!

EDIT: Fix repo link