8000 API: rename DivergingNorm to TwoSlopeNorm · matplotlib/matplotlib@a5d4505 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit a5d4505

Browse files
committed
API: rename DivergingNorm to TwoSlopeNorm
closes #15336
1 parent 2eb0023 commit a5d4505

File tree

7 files changed

+61
-42
lines changed

7 files changed

+61
-42
lines changed

doc/api/colors_api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Classes
3434
Normalize
3535
PowerNorm
3636
SymLogNorm
37+
TwoSlopeNorm
3738

3839
Functions
3940
---------

doc/api/prev_api_changes/api_changes_3.2.0/deprecations.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ is deprecated.
260260

261261
``testing.jpl_units.UnitDbl.UnitDbl.checkUnits`` is deprecated.
262262

263+
``DivergingNorm`` renamed to ``TwoSlopeNorm``
264+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265+
266+
``DivergingNorm`` was a misleading name because it did not diverge (in
267+
the sense that it is not its self diverging, but is best used with
268+
diverging norms). It has been renamed to `.TwoSlopeNorm` to better represent
269+
the normalization function.
270+
263271
Misc
264272
~~~~
265273
``matplotlib.get_home`` is deprecated (use e.g. ``os.path.expanduser("~")``)

examples/userdemo/colormap_normalizations_diverging.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
=====================================
3-
DivergingNorm colormap normalization
4-
=====================================
2+
===================================
3+
TwoSlopeNorm colormap normalization
4+
===================================
55
66
Sometimes we want to have a different colormap on either side of a
77
conceptual center point, and we want those two colormaps to have
@@ -33,7 +33,7 @@
3333

3434
# make the norm: Note the center is offset so that the land has more
3535
# dynamic range:
36-
divnorm = colors.DivergingNorm(vmin=-500, vcenter=0, vmax=4000)
36+
divnorm = colors.TwoSlopeNorm(vmin=-500, vcenter=0, vmax=4000)
3737

3838
pcm = ax.pcolormesh(longitude, latitude, topo, rasterized=True, norm=divnorm,
3939
cmap=terrain_map,)

lib/matplotlib/colors.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ def scaled(self):
10601060
return self.vmin is not None and self.vmax is not None
10611061

10621062

1063-
class DivergingNorm(Normalize):
1063+
class TwoSlopeNorm(Normalize):
10641064
def __init__(self, vcenter, vmin=None, vmax=None):
10651065
"""
10661066
Normalize data with a set center.
@@ -1086,8 +1086,8 @@ def __init__(self, vcenter, vmin=None, vmax=None):
10861086
between is linearly interpolated::
10871087
10881088
>>> import matplotlib.colors as mcolors
1089-
>>> offset = mcolors.DivergingNorm(vmin=-4000.,
1090-
vcenter=0., vmax=10000)
1089+
>>> offset = mcolors.TwoSlopeNorm(vmin=-4000.,
1090+
vcenter=0., vmax=10000)
10911091
>>> data = [-4000., -2000., 0., 2500., 5000., 7500., 10000.]
10921092
>>> offset(data)
10931093
array([0., 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])
@@ -1130,6 +1130,11 @@ def __call__(self, value, clip=None):
11301130
return result
11311131

11321132

1133+
@cbook.deprecation.deprecated('3.2', alternative='TwoSlopeNorm')
1134+
class DivergingNorm(TwoSlopeNorm):
1135+
...
1136+
1137+
11331138
class LogNorm(Normalize):
11341139
"""Normalize a given value to the 0-1 range on a log scale."""
11351140

lib/matplotlib/tests/test_colorbar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from matplotlib.testing.decorators import image_comparison
99
import matplotlib.pyplot as plt
1010
from matplotlib.colors import (BoundaryNorm, LogNorm, PowerNorm, Normalize,
11-
DivergingNorm)
11+
TwoSlopeNorm)
1212
from matplotlib.colorbar import ColorbarBase, _ColorbarLogLocator
1313
from matplotlib.ticker import FixedLocator
1414

@@ -536,7 +536,7 @@ def test_colorbar_inverted_ticks():
536536

537537

538538
def test_extend_colorbar_customnorm():
539-
# This was a funny error with DivergingNorm, maybe with other norms,
539+
# This was a funny error with TwoSlopeNorm, maybe with other norms,
540540
# when extend='both'
541541
N = 100
542542
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
@@ -546,7 +546,7 @@ def test_extend_colorbar_customnorm():
546546

547547
fig, ax = plt.subplots(2, 1)
548548
pcm = ax[0].pcolormesh(X, Y, Z,
549-
norm=DivergingNorm(vcenter=0., vmin=-2, vmax=1),
549+
norm=TwoSlopeNorm(vcenter=0., vmin=-2, vmax=1),
550550
cmap='RdBu_r')
551551
cb = fig.colorbar(pcm, ax=ax[0], extend='both')
552552
np.testing.assert_allclose(cb.ax.get_position().extents,

lib/matplotlib/tests/test_colors.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -295,91 +295,91 @@ def test_Normalize():
295295
assert 0 < norm(1 + 50 * eps) < 1
296296

297297

298-
def test_DivergingNorm_autoscale():
299-
norm = mcolors.DivergingNorm(vcenter=20)
298+
def test_TwoSlopeNorm_autoscale():
299+
norm = mcolors.TwoSlopeNorm(vcenter=20)
300300
norm.autoscale([10, 20, 30, 40])
301301
assert norm.vmin == 10.
302302
assert norm.vmax == 40.
303303

304304

305-
def test_DivergingNorm_autoscale_None_vmin():
306-
norm = mcolors.DivergingNorm(2, vmin=0, vmax=None)
305+
def test_TwoSlopeNorm_autoscale_None_vmin():
306+
norm = mcolors.TwoSlopeNorm(2, vmin=0, vmax=None)
307307
norm.autoscale_None([1, 2, 3, 4, 5])
308308
assert norm(5) == 1
309309
assert norm.vmax == 5
310310

311311

312-
def test_DivergingNorm_autoscale_None_vmax():
313-
norm = mcolors.DivergingNorm(2, vmin=None, vmax=10)
312+
def test_TwoSlopeNorm_autoscale_None_vmax():
313+
norm = mcolors.TwoSlopeNorm(2, vmin=None, vmax=10)
314314
norm.autoscale_None([1, 2, 3, 4, 5])
315315
assert norm(1) == 0
316316
assert norm.vmin == 1
317317

318318

319-
def test_DivergingNorm_scale():
320-
norm = mcolors.DivergingNorm(2)
319+
def test_TwoSlopeNorm_scale():
320+
norm = mcolors.TwoSlopeNorm(2)
321321
assert norm.scaled() is False
322322
norm([1, 2, 3, 4])
323323
assert norm.scaled() is True
324324

325325

326-
def test_DivergingNorm_scaleout_center():
326+
def test_TwoSlopeNorm_scaleout_center():
327327
# test the vmin never goes above vcenter
328-
norm = mcolors.DivergingNorm(vcenter=0)
328+
norm = mcolors.TwoSlopeNorm(vcenter=0)
329329
norm([1, 2, 3, 5])
330330
assert norm.vmin == 0
331331
assert norm.vmax == 5
332332

333333

334-
def test_DivergingNorm_scaleout_center_max():
334+
def test_TwoSlopeNorm_scaleout_center_max():
335335
# test the vmax never goes below vcenter
336-
norm = mcolors.DivergingNorm(vcenter=0)
336+
norm = mcolors.TwoSlopeNorm(vcenter=0)
337337
norm([-1, -2, -3, -5])
338338
assert norm.vmax == 0
339339
assert norm.vmin == -5
340340

341341

342-
def test_DivergingNorm_Even():
343-
norm = mcolors.DivergingNorm(vmin=-1, vcenter=0, vmax=4)
342+
def test_TwoSlopeNorm_Even():
343+
norm = mcolors.TwoSlopeNorm(vmin=-1, vcenter=0, vmax=4)
344344
vals = np.array([-1.0, -0.5, 0.0, 1.0, 2.0, 3.0, 4.0])
345345
expected = np.array([0.0, 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])
346346
assert_array_equal(norm(vals), expected)
347347

348348

349-
def test_DivergingNorm_Odd():
350-
norm = mcolors.DivergingNorm(vmin=-2, vcenter=0, vmax=5)
349+
def test_TwoSlopeNorm_Odd():
350+
norm = mcolors.TwoSlopeNorm(vmin=-2, vcenter=0, vmax=5)
351351
vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
352352
expected = np.array([0.0, 0.25, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
353353
assert_array_equal(norm(vals), expected)
354354

355355

356-
def test_DivergingNorm_VminEqualsVcenter():
356+
def test_TwoSlopeNorm_VminEqualsVcenter():
357357
with pytest.raises(ValueError):
358-
mcolors.DivergingNorm(vmin=-2, vcenter=-2, vmax=2)
358+
mcolors.TwoSlopeNorm(vmin=-2, vcenter=-2, vmax=2)
359359

360360

361-
def test_DivergingNorm_VmaxEqualsVcenter():
361+
def test_TwoSlopeNorm_VmaxEqualsVcenter():
362362
with pytest.raises(ValueError):
363-
mcolors.DivergingNorm(vmin=-2, vcenter=2, vmax=2)
363+
mcolors.TwoSlopeNorm(vmin=-2, vcenter=2, vmax=2)
364364

365365

366-
def test_DivergingNorm_VminGTVcenter():
366+
def test_TwoSlopeNorm_VminGTVcenter():
367367
with pytest.raises(ValueError):
368-
mcolors.DivergingNorm(vmin=10, vcenter=0, vmax=20)
368+
mcolors.TwoSlopeNorm(vmin=10, vcenter=0, vmax=20)
369369

370370

371-
def test_DivergingNorm_DivergingNorm_VminGTVmax():
371+
def test_TwoSlopeNorm_TwoSlopeNorm_VminGTVmax():
372372
with pytest.raises(ValueError):
373-
mcolors.DivergingNorm(vmin=10, vcenter=0, vmax=5)
373+
mcolors.TwoSlopeNorm(vmin=10, vcenter=0, vmax=5)
374374

375375

376-
def test_DivergingNorm_VcenterGTVmax():
376+
def test_TwoSlopeNorm_VcenterGTVmax():
377377
with pytest.raises(ValueError):
378-
mcolors.DivergingNorm(vmin=10, vcenter=25, vmax=20)
378+
mcolors.TwoSlopeNorm(vmin=10, vcenter=25, vmax=20)
379379

380380

381-
def test_DivergingNorm_premature_scaling():
382-
norm = mcolors.DivergingNorm(vcenter=2)
381+
def test_TwoSlopeNorm_premature_scaling():
382+
norm = mcolors.TwoSlopeNorm(vcenter=2)
383383
with pytest.raises(ValueError):
384384
norm.inverse(np.array([0.1, 0.5, 0.9]))
385385

@@ -915,3 +915,8 @@ def test_same_color():
915915
def test_hex_shorthand_notation():
916916
assert mcolors.same_color("#123", "#112233")
917917
assert mcolors.same_color("#123a", "#112233aa")
918+
919+
920+
def test_DivergingNorm_deprecated():
921+
with pytest.warns(cbook.MatplotlibDeprecationWarning):
922+
norm = mcolors.DivergingNorm(vcenter=0)

tutorials/colors/colormapnorms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@
188188

189189

190190
###############################################################################
191-
# DivergingNorm: Different mapping on either side of a center
192-
# -----------------------------------------------------------
191+
# TwoSlopeNorm: Different mapping on either side of a center
192+
# ----------------------------------------------------------
193193
#
194194
# Sometimes we want to have a different colormap on either side of a
195195
# conceptual center point, and we want those two colormaps to have
@@ -215,7 +215,7 @@
215215

216216
# make the norm: Note the 8C47 center is offset so that the land has more
217217
# dynamic range:
218-
divnorm = colors.DivergingNorm(vmin=-500., vcenter=0, vmax=4000)
218+
divnorm = colors.TwoSlopeNorm(vmin=-500., vcenter=0, vmax=4000)
219219

220220
pcm = ax.pcolormesh(longitude, latitude, topo, rasterized=True, norm=divnorm,
221221
cmap=terrain_map,)
@@ -230,7 +230,7 @@
230230
# Custom normalization: Manually implement two linear ranges
231231
# ----------------------------------------------------------
232232
#
233-
# The `.DivergingNorm` described above makes a useful example for
233+
# The `.TwoSlopeNorm` described above makes a useful example for
234234
# defining your own norm.
235235

236236
class MidpointNormalize(colors.Normalize):

0 commit comments

Comments
 (0)
0