Skip to content

Commit a00a909

Browse files
committed
Fix make_norm_from_scale __name__ when used inline.
`make_norm_from_scale` can be used "inline", rather than as a class decorator, to dynamically create norm classes. However, in that case, the second parameter (`base_norm_cls`) would normally be set to the root base norm class (`mcolors.Normalize`). In that case, we should generate a new `__name__` for the dynamically generated class, to avoid the slightly confusing situation of having two different classes both called `mcolors.Normalize`.
1 parent 9465538 commit a00a909

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/matplotlib/colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,8 @@ def inverse(self, value):
15611561
.reshape(np.shape(value)))
15621562
return value[0] if is_scalar else value
15631563

1564-
Norm.__name__ = base_norm_cls.__name__
1564+
Norm.__name__ = (f"{scale_cls.__name__}Norm" if base_norm_cls is Normalize
1565+
else base_norm_cls.__name__)
15651566
Norm.__qualname__ = base_norm_cls.__qualname__
15661567
Norm.__module__ = base_norm_cls.__module__
15671568
Norm.__doc__ = base_norm_cls.__doc__

lib/matplotlib/tests/test_colors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,3 +1475,9 @@ def test_norm_update_figs(fig_test, fig_ref):
14751475
# Force initial draw to make sure it isn't already stale
14761476
fig_test.canvas.draw()
14771477
norm.vmin, norm.vmax = 10, 90
1478+
1479+
1480+
def test_make_norm_from_scale_name():
1481+
logitnorm = mcolors.make_norm_from_scale(
1482+
mscale.LogitScale, mcolors.Normalize)
1483+
assert logitnorm.__name__ == "LogitScaleNorm"

0 commit comments

Comments
 (0)