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

Skip to content

Commit ca2b111

Browse files
committed
Subclass normalizers from Abstract Base Class
1 parent 28288e2 commit ca2b111

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5146,8 +5146,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
51465146
if not self._hold:
51475147
self.cla()
51485148

5149-
isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm))
5150-
if norm is not None and not isNorm:
5149+
if norm is not None and not isinstance(norm, mcolors.Norms):
51515150
msg = "'norm' must be an instance of 'mcolors.Normalize' " \
51525151
"or 'mcolors.BivariateNorm'"
51535152
raise ValueError(msg)
@@ -5483,8 +5482,7 @@ def pcolor(self, *args, **kwargs):
54835482
collection.set_alpha(alpha)
54845483
collection.set_array(C)
54855484

5486-
isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm))
5487-
if norm is not None and not isNorm:
5485+
if norm is not None and not isinstance(norm, mcolors.Norms):
54885486
msg = "'norm' must be an instance of 'mcolors.Normalize' " \
54895487
"or 'mcolors.BivariateNorm'"
54905488
raise ValueError(msg)
@@ -5764,8 +5762,8 @@ def pcolorfast(self, *args, **kwargs):
57645762
cmap = kwargs.pop('cmap', None)
57655763
vmin = kwargs.pop('vmin', None)
57665764
vmax = kwargs.pop('vmax', None)
5767-
isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm))
5768-
if norm is not None and not isNorm:
5765+
5766+
if norm is not None and not isinstance(norm, mcolors.Norms):
57695767
msg = "'norm' must be an instance of 'mcolors.Normalize' " \
57705768
"or 'mcolors.BivariateNorm'"
57715769
raise ValueError(msg)

lib/matplotlib/colors.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
import numpy as np
6969
import matplotlib.cbook as cbook
7070
from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS
71-
71+
from abc import ABCMeta
7272

7373
class _ColorMapping(dict):
7474
def __init__(self, mapping):
@@ -885,7 +885,14 @@ def reversed(self, name=None):
885885
raise NotImplementedError()
886886

887887

888-
class Normalize(object):
888+
class Norms:
889+
"""
890+
Abstract Base Class to group `Normalize` and `BivariateNorm`
891+
"""
892+
__metaclass__ = ABCMeta
893+
pass
894+
895+
class Normalize(Norms):
889896
"""
890897
A class which, when called, can normalize data into
891898
the ``[0.0, 1.0]`` interval.
@@ -1377,7 +1384,7 @@ def inverse(self, value):
13771384
return value
13781385

13791386

1380-
class BivariateNorm:
1387+
class BivariateNorm(Norms):
13811388
"""
13821389
Normalize a list of two values corresponding to two 1D normalizers
13831390
"""

lib/matplotlib/tests/test_colors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,3 +707,15 @@ def __add__(self, other):
707707
mcolors.SymLogNorm(3, vmax=5, linscale=1),
708708
mcolors.PowerNorm(1)]:
709709
assert_array_equal(norm(data.view(MyArray)), norm(data))
710+
711+
712+
@pytest.mark.parametrize('norm', [
713+
mcolors.Normalize(), mcolors.LogNorm(), mcolors.BivariateNorm()
714+
]
715+
)
716+
def test_abstract_base_class_norms(norm):
717+
"""
718+
Test that all types of normalizers subclasses Abstract Base class
719+
`colors.Norms`
720+
"""
721+
assert isinstance(norm, mcolors.Norms)

0 commit comments

Comments
 (0)