Skip to content

Commit 122fb4a

Browse files
committed
Merge pull request #3413 from astrofrog/fix-image-normalize-old-matplotlib
Fix issue with ImageNormalize not working with Matplotlib < 1.2 because Normalize used to be an old-style class
2 parents 1b98a55 + 3af8357 commit 122fb4a

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎astropy/visualization/mpl_normalize.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44

55
from __future__ import division, print_function
66

7+
from distutils.version import LooseVersion
8+
79
import numpy as np
810
from numpy import ma
911

1012
try:
13+
import matplotlib
14+
HAS_MATPLOTLIB = True
15+
MATPLOTLIB_LT_12 = LooseVersion(matplotlib.__version__) < LooseVersion("1.2.0")
1116
from matplotlib.colors import Normalize
1217
except ImportError:
18+
HAS_MATPLOTLIB = False
1319
class Normalize(object):
1420
def __init__(self, *args, **kwargs):
1521
raise ImportError("matplotlib is required in order to use this class")
@@ -33,7 +39,11 @@ class ImageNormalize(Normalize):
3339

3440
def __init__(self, vmin=None, vmax=None, stretch=None, clip=False):
3541

36-
super(ImageNormalize, self).__init__(vmin=vmin, vmax=vmax, clip=clip)
42+
if HAS_MATPLOTLIB and MATPLOTLIB_LT_12:
43+
# Normalize is an old-style class
44+
Normalize.__init__(self, vmin=vmin, vmax=vmax, clip=clip)
45+
else: # Normalize is a new-style class
46+
super(ImageNormalize, self).__init__(vmin=vmin, vmax=vmax, clip=clip)
3747

3848
self.vmin = vmin
3949
self.vmax = vmax

0 commit comments

Comments
 (0)