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

Skip to content

Commit 1d8eb25

Browse files
committed
OffsetNorm -> PiecewiseLinearNorm
1 parent 9a01b9f commit 1d8eb25

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
@@ -162,44 +162,44 @@ def test_process_value_array(self):
162162
assert_array_equal(res, np.array([5., 10.]))
163163

164164

165-
class BaseOffsetNorm(BaseNormMixin):
166-
normclass = mcolors.OffsetNorm
165+
class BasePiecewiseLinearNorm(BaseNormMixin):
166+
normclass = mcolors.PiecewiseLinearNorm
167167
test_inverse = False
168168

169-
class test_OffsetNorm_Even(BaseOffsetNorm):
169+
class test_PiecewiseLinearNorm_Even(BasePiecewiseLinearNorm):
170170
def setup(self):
171171
self.norm = self.normclass(vmin=-1, vcenter=0, vmax=4)
172172
self.vals = np.array([-1.0, -0.5, 0.0, 1.0, 2.0, 3.0, 4.0])
173173
self.expected = np.array([0.0, 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])
174174

175175

176-
class test_OffsetNorm_Odd(BaseOffsetNorm):
176+
class test_PiecewiseLinearNorm_Odd(BasePiecewiseLinearNorm):
177177
def setup(self):
178-
self.normclass = mcolors.OffsetNorm
178+
self.normclass = mcolors.PiecewiseLinearNorm
179179
self.norm = self.normclass(vmin=-2, vcenter=0, vmax=5)
180180
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
181181
self.expected = np.array([0.0, 0.25, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
182182

183183

184-
class test_OffsetNorm_AllNegative(BaseOffsetNorm):
184+
class test_PiecewiseLinearNorm_AllNegative(BasePiecewiseLinearNorm):
185185
def setup(self):
186-
self.normclass = mcolors.OffsetNorm
186+
self.normclass = mcolors.PiecewiseLinearNorm
187187
self.norm = self.normclass(vmin=-10, vcenter=-8, vmax=-2)
188188
self.vals = np.array([-10., -9., -8., -6., -4., -2.])
189189
self.expected = np.array([0.0, 0.25, 0.5, 0.666667, 0.833333, 1.0])
190190

191191

192-
class test_OffsetNorm_AllPositive(BaseOffsetNorm):
192+
class test_PiecewiseLinearNorm_AllPositive(BasePiecewiseLinearNorm):
193193
def setup(self):
194-
self.normclass = mcolors.OffsetNorm
194+
self.normclass = mcolors.PiecewiseLinearNorm
195195
self.norm = self.normclass(vmin=0, vcenter=3, vmax=9)
196196
self.vals = np.array([0., 1.5, 3., 4.5, 6.0, 7.5, 9.])
197197
self.expected = np.array([0.0, 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])
198198

199199

200-
class test_OffsetNorm_NoVs(BaseOffsetNorm):
200+
class test_PiecewiseLinearNorm_NoVs(BasePiecewiseLinearNorm):
201201
def setup(self):
202-
self.normclass = mcolors.OffsetNorm
202+
self.normclass = mcolors.PiecewiseLinearNorm
203203
self.norm = self.normclass(vmin=None, vcenter=None, vmax=None)
204204
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0])
205205
self.expected = np.array([0., 0.16666667, 0.33333333,
@@ -224,26 +224,26 @@ def test_vmax(self):
224224
nt.assert_equal(self.norm.vmax, self.expected_vmax)
225225

226226

227-
class test_OffsetNorm_VminEqualsVcenter(BaseOffsetNorm):
227+
class test_PiecewiseLinearNorm_VminEqualsVcenter(BasePiecewiseLinearNorm):
228228
def setup(self):
229-
self.normclass = mcolors.OffsetNorm
229+
self.normclass = mcolors.PiecewiseLinearNorm
230230
self.norm = self.normclass(vmin=-2, vcenter=-2, vmax=2)
231231
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
232232
self.expected = np.array([0.5, 0.625, 0.75, 0.875, 1.0])
233233

234234

235-
class test_OffsetNorm_VmaxEqualsVcenter(BaseOffsetNorm):
235+
class test_PiecewiseLinearNorm_VmaxEqualsVcenter(BasePiecewiseLinearNorm):
236236
def setup(self):
237-
self.normclass = mcolors.OffsetNorm
237+
self.normclass = mcolors.PiecewiseLinearNorm
238238
self.norm = self.normclass(vmin=-2, vcenter=2, vmax=2)
239239
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
240240
self.expected = np.array([0.0, 0.125, 0.25, 0.375, 0.5])
241241

242242

243-
class test_OffsetNorm_VsAllEqual(BaseOffsetNorm):
243+
class test_PiecewiseLinearNorm_VsAllEqual(BasePiecewiseLinearNorm):
244244
def setup(self):
245245
self.v = 10
246-
self.normclass = mcolors.OffsetNorm
246+
self.normclass = mcolors.PiecewiseLinearNorm
247247
self.norm = self.normclass(vmin=self.v, vcenter=self.v, vmax=self.v)
248248
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
249249
self.expected = np.array([0.0, 0.0, 0.0, 0.0, 0.0])
@@ -256,28 +256,28 @@ def test_inverse(self):
256256
)
257257

258258

259-
class test_OffsetNorm_Errors(object):
259+
class test_PiecewiseLinearNorm_Errors(object):
260260
def setup(self):
261261
self.vals = np.arange(50)
262262

263263
@nt.raises(ValueError)
264264
def test_VminGTVcenter(self):
265-
norm = mcolors.OffsetNorm(vmin=10, vcenter=0, vmax=20)
265+
norm = mcolors.PiecewiseLinearNorm(vmin=10, vcenter=0, vmax=20)
266266
norm(self.vals)
267267

268268
@nt.raises(ValueError)
269269
def test_VminGTVmax(self):
270-
norm = mcolors.OffsetNorm(vmin=10, vcenter=0, vmax=5)
270+
norm = mcolors.PiecewiseLinearNorm(vmin=10, vcenter=0, vmax=5)
271271
norm(self.vals)
272272

273273
@nt.raises(ValueError)
274274
def test_VcenterGTVmax(self):
275-
norm = mcolors.OffsetNorm(vmin=10, vcenter=25, vmax=20)
275+
norm = mcolors.PiecewiseLinearNorm(vmin=10, vcenter=25, vmax=20)
276276
norm(self.vals)
277277

278278
@nt.raises(ValueError)
279279
def test_premature_scaling(self):
280-
norm = mcolors.OffsetNorm()
280+
norm = mcolors.PiecewiseLinearNorm()
281281
norm.inverse(np.array([0.1, 0.5, 0.9]))
282282

283283

@@ -290,7 +290,7 @@ def test_offset_norm_img():
290290

291291
fig, (ax1, ax2) = plt.subplots(ncols=2)
292292
cmap = plt.cm.coolwarm
293-
norm = mcolors.OffsetNorm(vmin=-2, vcenter=0, vmax=7)
293+
norm = mcolors.PiecewiseLinearNorm(vmin=-2, vcenter=0, vmax=7)
294294

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

0 commit comments

Comments
 (0)