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

Skip to content

Commit ad2687d

Browse files
committed
Subclass normalizers from Abstract Base Class
1 parent 50010e7 commit ad2687d

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
@@ -5128,8 +5128,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
51285128
if not self._hold:
51295129
self.cla()
51305130

5131-
isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm))
5132-
if norm is not None and not isNorm:
5131+
if norm is not None and not isinstance(norm, mcolors.Norms):
51335132
msg = "'norm' must be an instance of 'mcolors.Normalize' " \
51345133
"or 'mcolors.BivariateNorm'"
51355134
raise ValueError(msg)
@@ -5468,8 +5467,7 @@ def pcolor(self, *args, **kwargs):
54685467
collection.set_alpha(alpha)
54695468
collection.set_array(C)
54705469

5471-
isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm))
5472-
if norm is not None and not isNorm:
5470+
if norm is not None and not isinstance(norm, mcolors.Norms):
54735471
msg = "'norm' must be an instance of 'mcolors.Normalize' " \
54745472
"or 'mcolors.BivariateNorm'"
54755473
raise ValueError(msg)
@@ -5749,8 +5747,8 @@ def pcolorfast(self, *args, **kwargs):
57495747
cmap = kwargs.pop('cmap', None)
57505748
vmin = kwargs.pop('vmin', None)
57515749
vmax = kwargs.pop('vmax', None)
5752-
isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm))
5753-
if norm is not None and not isNorm:
5750+
5751+
if norm is not None and not isinstance(norm, mcolors.Norms):
57545752
msg = "'norm' must be an instance of 'mcolors.Normalize' " \
57555753
"or 'mcolors.BivariateNorm'"
57565754
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):
@@ -882,7 +882,14 @@ def reversed(self, name=None):
882882
raise NotImplementedError()
883883

884884

885-
class Normalize(object):
885+
class Norms:
886+
"""
887+
Abstract Base Class to group `Normalize` and `BivariateNorm`
888+
"""
889+
__metaclass__ = ABCMeta
890+
pass
891+
892+
class Normalize(Norms):
886893
"""
887894
A class which, when called, can normalize data into
888895
the ``[0.0, 1.0]`` interval.
@@ -1374,7 +1381,7 @@ def inverse(self, value):
13741381
return value
13751382

13761383

1377-
class BivariateNorm:
1384+
class BivariateNorm(Norms):
13781385
"""
13791386
Normalize a list of two values corresponding to two 1D normalizers
13801387
"""

lib/matplotlib/tests/test_colors.py

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

0 commit comments

Comments
 (0)