FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix cmap deprecations by QuLogic · Pull Request #23710 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/behavior/23710-ES.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
``plt.get_cmap`` and ``matplotlib.cm.get_cmap`` return a copy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Formerly, `~.pyplot.get_cmap` and `.cm.get_cmap` returned a global version of a
`.Colormap`. This was prone to errors as modification of the colormap would
propagate from one location to another without warning. Now, a new copy of the
colormap is returned.
7 changes: 4 additions & 3 deletions lib/matplotlib/cm.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def unregister(self, name):
@_api.deprecated(
'3.6',
pending=True,
alternative="``matplotlib.colormaps.register_cmap(name)``"
alternative="``matplotlib.colormaps.register(name)``"
)
def register_cmap(name=None, cmap=None, *, override_builtin=False):
"""
Expand Down Expand Up @@ -280,14 +280,15 @@ def _get_cmap(name=None, lut=None):
# do it in two steps like this so we can have an un-deprecated version in
# pyplot.
get_cmap = _api.deprecated(
'3.6', pending=True, alternative="``matplotlib.colormaps[name]``"
'3.6',
name='get_cmap', pending=True, alternative="``matplotlib.colormaps[name]``"
)(_get_cmap)


@_api.deprecated(
'3.6',
pending=True,
alternative="``matplotlib.colormaps.unregister_cmap(name)``"
alternative="``matplotlib.colormaps.unregister(name)``"
)
def unregister_cmap(name):
"""
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/tests/test_colors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_register_cmap():
target = "viridis2"
with pytest.warns(
PendingDeprecationWarning,
match=r"matplotlib\.colormaps\.register_cmap\(name\)"
match=r"matplotlib\.colormaps\.register\(name\)"
):
cm.register_cmap(target, new_cm)
assert mpl.colormaps[target] == new_cm
Expand All @@ -78,13 +78,13 @@ def test_register_cmap():
match="Arguments must include a name or a Colormap"):
with pytest.warns(
PendingDeprecationWarning,
match=r"matplotlib\.colormaps\.register_cmap\(name\)"
match=r"matplotlib\.colormaps\.register\(name\)"
):
cm.register_cmap()

with pytest.warns(
PendingDeprecationWarning,
match=r"matplotlib\.colormaps\.unregister_cmap\(name\)"
match=r"matplotlib\.colormaps\.unregister\(name\)"
):
cm.unregister_cmap(target)
with pytest.raises(ValueError,
Expand All @@ -96,15 +96,15 @@ def test_register_cmap():
cm.get_cmap(target)
with pytest.warns(
PendingDeprecationWarning,
match=r"matplotlib\.colormaps\.unregister_cmap\(name\)"
match=r"matplotlib\.colormaps\.unregister\(name\)"
):
# test that second time is error free
cm.unregister_cmap(target)

with pytest.raises(TypeError, match="'cmap' must be"):
with pytest.warns(
PendingDeprecationWarning,
match=r"matplotlib\.colormaps\.register_cmap\(name\)"
match=r"matplotlib\.colormaps\.register\(name\)"
):
cm.register_cmap('nome', cmap='not a cmap')

Expand Down

Back | FazBrowse Home | New Git URL