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

Skip to content

Commit 36042b6

Browse files
dopplershiftOceanWolf
authored andcommitted
OffsetNorm -> PiecewiseLinearNorm
1 parent 47c447a commit 36042b6

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

doc/users/whats_new.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ determines the placement of the arrow head along the quiver line.
6262

6363
Offset Normalizers for Colormaps
6464
````````````````````````````````
65-
Paul Hobson/Geosyntec Consultants added a new :class:`matplotlib.colors.OffsetNorm`
65+
Paul Hobson/Geosyntec Consultants added a new :class:`matplotlib.colors.PiecewiseLinearNorm`
6666
class with the help of Till Stensitzki. This is particularly useful when using a
6767
diverging colormap on data that are asymetrically centered around a logical value
6868
(e.g., 0 when data range from -2 to 4).

lib/matplotlib/colors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ def scaled(self):
964964
return (self.vmin is not None and self.vmax is not None)
965965

966966

967-
class OffsetNorm(Normalize):
967+
class PiecewiseLinearNorm(Normalize):
968968
"""
969969
A subclass of matplotlib.colors.Normalize.
970970
@@ -998,7 +998,7 @@ def __init__(self, vmin=None, vcenter=None, vmax=None, clip=False):
998998
Examples
999999
--------
10001000
>>> import matplotlib.colors as mcolors
1001-
>>> offset = mcolors.OffsetNorm(vmin=-2., vcenter=0., vmax=4.)
1001+
>>> offset = mcolors.PiecewiseLinearNorm(vmin=-2., vcenter=0., vmax=4.)
10021002
>>> data = [-2., -1., 0., 1., 2., 3., 4.]
10031003
>>> offset(data)
10041004
array([0., 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])

lib/matplotlib/tests/test_colors.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -227,44 +227,44 @@ def test_process_value_array(self):
227227
assert_array_equal(res, np.array([5., 10.]))
228228

229229

230-
class BaseOffsetNorm(BaseNormMixin):
231-
normclass = mcolors.OffsetNorm
230+
class BasePiecewiseLinearNorm(BaseNormMixin):
231+
normclass = mcolors.PiecewiseLinearNorm
232232
test_inverse = False
233233

234-
class test_OffsetNorm_Even(BaseOffsetNorm):
234+
class test_PiecewiseLinearNorm_Even(BasePiecewiseLinearNorm):
235235
def setup(self):
236236
self.norm = self.normclass(vmin=-1, vcenter=0, vmax=4)
237237
self.vals = np.array([-1.0, -0.5, 0.0, 1.0, 2.0, 3.0, 4.0])
238238
self.expected = np.array([0.0, 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])
239239

240240

241-
class test_OffsetNorm_Odd(BaseOffsetNorm):
241+
class test_PiecewiseLinearNorm_Odd(BasePiecewiseLinearNorm):
242242
def setup(self):
243-
self.normclass = mcolors.OffsetNorm
243+
self.normclass = mcolors.PiecewiseLinearNorm
244244
self.norm = self.normclass(vmin=-2, vcenter=0, vmax=5)
245245
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
246246
self.expected = np.array([0.0, 0.25, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
247247

248248

249-
class test_OffsetNorm_AllNegative(BaseOffsetNorm):
249+
class test_PiecewiseLinearNorm_AllNegative(BasePiecewiseLinearNorm):
250250
def setup(self):
251-
self.normclass = mcolors.OffsetNorm
251+
self.normclass = mcolors.PiecewiseLinearNorm
252252
self.norm = self.normclass(vmin=-10, vcenter=-8, vmax=-2)
253253
self.vals = np.array([-10., -9., -8., -6., -4., -2.])
254254
self.expected = np.array([0.0, 0.25, 0.5, 0.666667, 0.833333, 1.0])
255255

256256

257-
class test_OffsetNorm_AllPositive(BaseOffsetNorm):
257+
class test_PiecewiseLinearNorm_AllPositive(BasePiecewiseLinearNorm):
258258
def setup(self):
259-
self.normclass = mcolors.OffsetNorm
259+
self.normclass = mcolors.PiecewiseLinearNorm
260260
self.norm = self.normclass(vmin=0, vcenter=3, vmax=9)
261261
self.vals = np.array([0., 1.5, 3., 4.5, 6.0, 7.5, 9.])
262262
self.expected = np.array([0.0, 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])
263263

264264

265-
class test_OffsetNorm_NoVs(BaseOffsetNorm):
265+
class test_PiecewiseLinearNorm_NoVs(BasePiecewiseLinearNorm):
266266
def setup(self):
267-
self.normclass = mcolors.OffsetNorm
267+
self.normclass = mcolors.PiecewiseLinearNorm
268268
self.norm = self.normclass(vmin=None, vcenter=None, vmax=None)
269269
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0])
270270
self.expected = np.array([0., 0.16666667, 0.33333333,
@@ -289,26 +289,26 @@ def test_vmax(self):
289289
assert_equal(self.norm.vmax, self.expected_vmax)
290290

291291

292-
class test_OffsetNorm_VminEqualsVcenter(BaseOffsetNorm):
292+
class test_PiecewiseLinearNorm_VminEqualsVcenter(BasePiecewiseLinearNorm):
293293
def setup(self):
294-
self.normclass = mcolors.OffsetNorm
294+
self.normclass = mcolors.PiecewiseLinearNorm
295295
self.norm = self.normclass(vmin=-2, vcenter=-2, vmax=2)
296296
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
297297
self.expected = np.array([0.5, 0.625, 0.75, 0.875, 1.0])
298298

299299

300-
class test_OffsetNorm_VmaxEqualsVcenter(BaseOffsetNorm):
300+
class test_PiecewiseLinearNorm_VmaxEqualsVcenter(BasePiecewiseLinearNorm):
301301
def setup(self):
302-
self.normclass = mcolors.OffsetNorm
302+
self.normclass = mcolors.PiecewiseLinearNorm
303303
self.norm = self.normclass(vmin=-2, vcenter=2, vmax=2)
304304
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
305305
self.expected = np.array([0.0, 0.125, 0.25, 0.375, 0.5])
306306

307307

308-
class test_OffsetNorm_VsAllEqual(BaseOffsetNorm):
308+
class test_PiecewiseLinearNorm_VsAllEqual(BasePiecewiseLinearNorm):
309309
def setup(self):
310310
self.v = 10
311-
self.normclass = mcolors.OffsetNorm
311+
self.normclass = mcolors.PiecewiseLinearNorm
312312
self.norm = self.normclass(vmin=self.v, vcenter=self.v, vmax=self.v)
313313
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
314314
self.expected = np.array([0.0, 0.0, 0.0, 0.0, 0.0])
@@ -321,28 +321,28 @@ def test_inverse(self):
321321
)
322322

323323

324-
class test_OffsetNorm_Errors(object):
324+
class test_PiecewiseLinearNorm_Errors(object):
325325
def setup(self):
326326
self.vals = np.arange(50)
327327

328328
@raises(ValueError)
329329
def test_VminGTVcenter(self):
330-
norm = mcolors.OffsetNorm(vmin=10, vcenter=0, vmax=20)
330+
norm = mcolors.PiecewiseLinearNorm(vmin=10, vcenter=0, vmax=20)
331331
norm(self.vals)
332332

333333
@raises(ValueError)
334334
def test_VminGTVmax(self):
335-
norm = mcolors.OffsetNorm(vmin=10, vcenter=0, vmax=5)
335+
norm = mcolors.PiecewiseLinearNorm(vmin=10, vcenter=0, vmax=5)
336336
norm(self.vals)
337337

338338
@raises(ValueError)
339339
def test_VcenterGTVmax(self):
340-
norm = mcolors.OffsetNorm(vmin=10, vcenter=25, vmax=20)
340+
norm = mcolors.PiecewiseLinearNorm(vmin=10, vcenter=25, vmax=20)
341341
norm(self.vals)
342342

343343
@raises(ValueError)
344344
def test_premature_scaling(self):
345-
norm = mcolors.OffsetNorm()
345+
norm = mcolors.PiecewiseLinearNorm()
346346
norm.inverse(np.array([0.1, 0.5, 0.9]))
347347

348348

@@ -355,7 +355,7 @@ def test_offset_norm_img():
355355

356356
fig, (ax1, ax2) = plt.subplots(ncols=2)
357357
cmap = plt.cm.coolwarm
358-
norm = mcolors.OffsetNorm(vmin=-2, vcenter=0, vmax=7)
358+
norm = mcolors.PiecewiseLinearNorm(vmin=-2, vcenter=0, vmax=7)
359359

360360
img1 = ax1.imshow(Z, cmap=cmap, norm=None)
361361
cbar1 = fig.colorbar(img1, ax=ax1)

0 commit comments

Comments
 (0)