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

Skip to content

Commit 2d41664

Browse files
committed
WIP: added symmetrical norm
1 parent 37ff5a5 commit 2d41664

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/matplotlib/colors.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def rgb2hex(rgb):
225225
a = '#%02x%02x%02x' % tuple([int(np.round(val * 255)) for val in rgb[:3]])
226226
return a
227227

228+
228229
hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z")
229230

230231

@@ -1043,6 +1044,14 @@ def inverse(self, value):
10431044
return inverted[0]
10441045

10451046

1047+
class SymmetricalNorm(Normalize):
1048+
def __init__(self, vmin=None, vmax=None, clip=False):
1049+
limit = np.max(np.abs([vmin, vmax]))
1050+
self.vmin = limit * -1
1051+
self.vmax = limit
1052+
self.clip = clip
1053+
1054+
10461055
class LogNorm(Normalize):
10471056
"""
10481057
Normalize a given value to the 0-1 range on a log scale

lib/matplotlib/tests/test_colors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,21 @@ def setup(self):
101101
self.vals = np.array([-1, -0.5, 0.0, 1.0, 2.0, 3.0, 4.0])
102102
self.expected = np.array([0.0, 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])
103103

104+
104105
class test_OffsetNorm_Even(_base_NormMixin):
105106
def setup(self):
106107
self.norm = mcolors.OffsetNorm(vmin=-2, vcenter=0, vmax=5)
107108
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
108109
self.expected = np.array([0.0, 0.25, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
109110

110111

112+
class test_SymmetricalNorm(_base_NormMixin):
113+
def setup(self):
114+
self.norm = mcolors.SymmetricalNorm(vmin=-2, vmax=4)
115+
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0])
116+
self.expected = np.array([0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0])
117+
118+
111119
def test_SymLogNorm():
112120
"""
113121
Test SymLogNorm behavior

0 commit comments

Comments
 (0)