Skip to content

Navigation Menu

Sign in
Appearance settings

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

Appearance settings

Commit 739252b

Browse filesBrowse files
authored
Merge pull request #20405 from jklymak/enh-expose-make_norm_from_scale
ENH: expose make_norm_from_scale
2 parents cbc4e35 + 4ec0bc2 commit 739252b
Copy full SHA for 739252b

File tree

Expand file treeCollapse file tree

3 files changed

+18
-8
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+18
-8
lines changed

‎doc/api/colors_api.rst

Copy file name to clipboardExpand all lines: doc/api/colors_api.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ Functions
5252
is_color_like
5353
same_color
5454
get_named_colors_mapping
55+
make_norm_from_scale
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Make norm from scale now public
2+
===============================
3+
4+
Downstream libraries can take advantage of `.colors.make_norm_from_scale`
5+
to create a `~.colors.Normalize` subclass directly from an existing scale.
6+
Usually norms have a scale, and the advantage of having a `~.scale.ScaleBase`
7+
attached to a norm is to provide a scale, and associated tick locators and
8+
formatters, for the colorbar.

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+9-8Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,13 +1415,14 @@ def __call__(self, value, clip=None):
14151415
return super().__call__(value, clip=clip)
14161416

14171417

1418-
def _make_norm_from_scale(scale_cls, base_norm_cls=None, *, init=None):
1418+
def make_norm_from_scale(scale_cls, base_norm_cls=None, *, init=None):
14191419
"""
1420-
Decorator for building a `.Normalize` subclass from a `.Scale` subclass.
1420+
Decorator for building a `.Normalize` subclass from a `~.scale.ScaleBase`
1421+
subclass.
14211422
14221423
After ::
14231424
1424-
@_make_norm_from_scale(scale_cls)
1425+
@make_norm_from_scale(scale_cls)
14251426
class norm_cls(Normalize):
14261427
...
14271428
@@ -1436,7 +1437,7 @@ class norm_cls(Normalize):
14361437
a dummy axis).
14371438
14381439
If the *scale_cls* constructor takes additional parameters, then *init*
1439-
should be passed to `_make_norm_from_scale`. It is a callable which is
1440+
should be passed to `make_norm_from_scale`. It is a callable which is
14401441
*only* used for its signature. First, this signature will become the
14411442
signature of *norm_cls*. Second, the *norm_cls* constructor will bind the
14421443
parameters passed to it using this signature, extract the bound *vmin*,
@@ -1446,7 +1447,7 @@ class norm_cls(Normalize):
14461447
"""
14471448

14481449
if base_norm_cls is None:
1449-
return functools.partial(_make_norm_from_scale, scale_cls, init=init)
1450+
return functools.partial(make_norm_from_scale, scale_cls, init=init)
14501451

14511452
if init is None:
14521453
def init(vmin=None, vmax=None, clip=False): pass
@@ -1509,7 +1510,7 @@ def inverse(self, value):
15091510
return Norm
15101511

15111512

1512-
@_make_norm_from_scale(
1513+
@make_norm_from_scale(
15131514
scale.FuncScale,
15141515
init=lambda functions, vmin=None, vmax=None, clip=False: None)
15151516
class FuncNorm(Normalize):
@@ -1542,7 +1543,7 @@ def forward(values: array-like) -> array-like
15421543
"""
15431544

15441545

1545-
@_make_norm_from_scale(functools.partial(scale.LogScale, nonpositive="mask"))
1546+
@make_norm_from_scale(functools.partial(scale.LogScale, nonpositive="mask"))
15461547
class LogNorm(Normalize):
15471548
"""Normalize a given value to the 0-1 range on a log scale."""
15481549

@@ -1555,7 +1556,7 @@ def autoscale_None(self, A):
15551556
super().autoscale_None(np.ma.array(A, mask=(A <= 0)))
15561557

15571558

1558-
@_make_norm_from_scale(
1559+
@make_norm_from_scale(
15591560
scale.SymmetricalLogScale,
15601561
init=lambda linthresh, linscale=1., vmin=None, vmax=None, clip=False, *,
15611562
base=10: None)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.