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

Skip to content

Commit e2090f4

Browse files
committed
MNT: Pending-deprecate setting colormap extremes
Per #29141 we have the long-term plan to make colormaps immutable. As a result, the in-place modifications have to be removed. We take this particularly slow with at least two minor releases of pending deprecation and two further releases of actual deprecations. As it's quite a common concept and migrating away will take time.
1 parent 352b419 commit e2090f4

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
In-place modifications of colormaps
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Colormaps are planned to become immuatable in the long term.
4+
5+
As a first step, in-place modifications of colormaps are now pending-deprecated.
6+
This affects the following methods of `.Colormap`:
7+
8+
- `.Colormap.set_bad` - use ``cmap.with_extremes(bad=...)`` instead
9+
- `.Colormap.set_under` - use ``cmap.with_extremes(under=...)`` instead
10+
- `.Colormap.set_over` - use ``cmap.with_extremes(over=...)`` instead
11+
- `.Colormap.set_extremes` - use ``cmap.with_extremes(...)`` instead
12+
13+
Use the respective `.Colormap.with_extremes` and appropriate keyword arguments
14+
instead with returns a copy of the colormap (available since matplotlib 3.4).
15+
Alternatively, if you create the colormap yourself, you can also pass the
16+
respective arguments to the constructor (available since matplotlib 3.11).

lib/matplotlib/colors.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,10 @@ def get_bad(self):
875875
self._init()
876876
return np.array(self._lut[self._i_bad])
877877

878+
@_api.deprecated(
879+
"3.11",
880+
pending=True,
881+
alternative="cmap.with_extremes(bad=...) or Colormap(bad=...)")
878882
def set_bad(self, color='k', alpha=None):
879883
"""Set the color for masked values."""
880884
self._rgba_bad = to_rgba(color, alpha)
@@ -887,6 +891,10 @@ def get_under(self):
887891
self._init()
888892
return np.array(self._lut[self._i_under])
889893

894+
@_api.deprecated(
895+
"3.11",
896+
pending=True,
897+
alternative="cmap.with_extremes(under=...) or Colormap(under=...)")
890898
def set_under(self, color='k', alpha=None):
891899
"""Set the color for low out-of-range values."""
892900
self._rgba_under = to_rgba(color, alpha)
@@ -899,12 +907,21 @@ def get_over(self):
899907
self._init()
900908
return np.array(self._lut[self._i_over])
901909

910+
@_api.deprecated(
911+
"3.11",
912+
pending=True,
913+
alternative="cmap.with_extremes(over=...) or Colormap(over=...)")
902914
def set_over(self, color='k', alpha=None):
903915
"""Set the color for high out-of-range values."""
904916
self._rgba_over = to_rgba(color, alpha)
905917
if self._isinit:
906918
self._set_extremes()
907919

920+
@_api.deprecated(
921+
"3.11",
922+
pending=True,
923+
alternative="cmap.with_extremes(bad=..., under=..., over=...) or "
924+
"Colormap(bad=..., under=..., over=...)")
908925
def set_extremes(self, *, bad=None, under=None, over=None):
909926
"""
910927
Set the colors for masked (*bad*) values and, when ``norm.clip =

0 commit comments

Comments
 (0)