From 12c9d664d286507d48c4416936c9e0557701fbab Mon Sep 17 00:00:00 2001 From: Diksha <228217662+dikshajangra12918-oss@users.noreply.github.com> Date: Tue, 21 Apr 2026 15:25:40 +0530 Subject: [PATCH 01/16] Add unregister_scale() function to matplotlib.scale Added unregister_scale(name) function that allows users to remove previously registered custom scales from the registry. Raises ValueError if the scale name is not found. --- lib/matplotlib/scale.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index 0793bb31e566..8b6cf9706ac6 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -955,6 +955,19 @@ def register_scale(scale_class): pending=True, ) +def unregister_scale(name): + """ + Remove a custom scale from the registry. + + Parameters + ---------- + name : str + The name of the scale to remove. + """ + if name not in _scale_mapping: + raise ValueError(f"Scale '{name}' is not registered.") + del _scale_mapping[name] + def _get_scale_docs(): """ From 9536088616ac519d48390214605206061ec0a0ad Mon Sep 17 00:00:00 2001 From: Diksha <228217662+dikshajangra12918-oss@users.noreply.github.com> Date: Tue, 21 Apr 2026 15:38:40 +0530 Subject: [PATCH 02/16] Add tests for unregister_scale function Added two test cases in test_scale.py: 1. test_unregister_scale: registers a temporary custom scale and verifies it is removed correctly. 2. test_unregister_scale_invalid: verifies that ValueError is raised when trying to unregister a scale that doesn't exist. --- lib/matplotlib/tests/test_scale.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index 9f882103967e..d656ffff711a 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -433,3 +433,22 @@ def test_val_in_range_base_fallback(): assert s.val_in_range(np.nan) is False assert s.val_in_range(np.inf) is False assert s.val_in_range(-np.inf) is False + +def test_unregister_scale(): + """Test that unregister_scale removes a scale correctly.""" + # Register a temporary custom scale + class TempScale(mscale.LinearScale): + name = 'temp_test_scale' + + mscale.register_scale(TempScale) + assert 'temp_test_scale' in mscale._scale_mapping + + # Now unregister it + mscale.unregister_scale('temp_test_scale') + assert 'temp_test_scale' not in mscale._scale_mapping + + +def test_unregister_scale_invalid(): + """Test that unregister_scale raises ValueError for unknown scale.""" + with pytest.raises(ValueError, match="not registered"): + mscale.unregister_scale('this_does_not_exist') From 0a4417d312c7f937b1488ac01ecb6b962cc650e9 Mon Sep 17 00:00:00 2001 From: apple Date: Wed, 22 Apr 2026 18:49:38 +0530 Subject: [PATCH 03/16] Use pop() instead of del for removing scale --- lib/matplotlib/scale.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index 8b6cf9706ac6..cb6c22b96c9e 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -955,6 +955,7 @@ def register_scale(scale_class): pending=True, ) + def unregister_scale(name): """ Remove a custom scale from the registry. @@ -966,7 +967,7 @@ def unregister_scale(name): """ if name not in _scale_mapping: raise ValueError(f"Scale '{name}' is not registered.") - del _scale_mapping[name] + _scale_mapping.pop(name) def _get_scale_docs(): From cc686b1f1c7249f28605cf962630c0231b874918 Mon Sep 17 00:00:00 2001 From: apple Date: Wed, 22 Apr 2026 22:49:13 +0530 Subject: [PATCH 04/16] Also remove from _scale_has_axis_parameter in unregister_scale --- lib/matplotlib/scale.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index cb6c22b96c9e..62091e35252f 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -968,6 +968,7 @@ def unregister_scale(name): if name not in _scale_mapping: raise ValueError(f"Scale '{name}' is not registered.") _scale_mapping.pop(name) + _scale_has_axis_parameter.pop(name, None) def _get_scale_docs(): From 99690bcef1703636503ad92e67c276ec2e826b05 Mon Sep 17 00:00:00 2001 From: apple Date: Wed, 22 Apr 2026 22:58:54 +0530 Subject: [PATCH 05/16] Fix formatting in test_unregister_scale --- lib/matplotlib/tests/test_scale.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index d656ffff711a..b05edb0fdc2a 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -433,6 +433,7 @@ def test_val_in_range_base_fallback(): assert s.val_in_range(np.nan) is False assert s.val_in_range(np.inf) is False assert s.val_in_range(-np.inf) is False + def test_unregister_scale(): """Test that unregister_scale removes a scale correctly.""" From d9bf8cf80fea60986d3e0ccf4f303fc115f0811b Mon Sep 17 00:00:00 2001 From: apple Date: Wed, 22 Apr 2026 23:21:12 +0530 Subject: [PATCH 06/16] Remove whitespace from blank line --- lib/matplotlib/tests/test_scale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index b05edb0fdc2a..35106fc54530 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -433,7 +433,7 @@ def test_val_in_range_base_fallback(): assert s.val_in_range(np.nan) is False assert s.val_in_range(np.inf) is False assert s.val_in_range(-np.inf) is False - + def test_unregister_scale(): """Test that unregister_scale removes a scale correctly.""" From 2747f55204152c70babf3c649643069bf0e1bf53 Mon Sep 17 00:00:00 2001 From: Diksha <228217662+dikshajangra12918-oss@users.noreply.github.com> Date: Thu, 23 Apr 2026 05:10:44 +0530 Subject: [PATCH 07/16] Update lib/matplotlib/scale.py Co-authored-by: hannah --- lib/matplotlib/scale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index 62091e35252f..de4968dd1aeb 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -956,7 +956,7 @@ def register_scale(scale_class): ) -def unregister_scale(name): +def deregister_scale(name): """ Remove a custom scale from the registry. From e673532d38b106bab9a50b300d3994ae7168103c Mon Sep 17 00:00:00 2001 From: apple Date: Thu, 23 Apr 2026 05:18:40 +0530 Subject: [PATCH 08/16] Add deregister_scale to stub file --- lib/matplotlib/scale.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/scale.pyi b/lib/matplotlib/scale.pyi index 866509ee020d..f553fb92fe81 100644 --- a/lib/matplotlib/scale.pyi +++ b/lib/matplotlib/scale.pyi @@ -182,4 +182,5 @@ class LogitScale(ScaleBase): def get_scale_names() -> list[str]: ... def scale_factory(scale: str, axis: Axis, **kwargs) -> ScaleBase: ... def register_scale(scale_class: type[ScaleBase]) -> None: ... +def deregister_scale(name: str) -> None: ... def _make_axis_parameter_optional(init_func: Callable[..., None]) -> Callable[..., None]: ... From d56e2ef007a368dd4032989f2e752b7c89125152 Mon Sep 17 00:00:00 2001 From: apple Date: Thu, 23 Apr 2026 14:43:26 +0530 Subject: [PATCH 09/16] Update tests to use deregister_scale --- lib/matplotlib/tests/test_scale.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index 35106fc54530..0b51fb688311 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -445,11 +445,11 @@ class TempScale(mscale.LinearScale): assert 'temp_test_scale' in mscale._scale_mapping # Now unregister it - mscale.unregister_scale('temp_test_scale') + mscale.deregister_scale('temp_test_scale') assert 'temp_test_scale' not in mscale._scale_mapping def test_unregister_scale_invalid(): """Test that unregister_scale raises ValueError for unknown scale.""" with pytest.raises(ValueError, match="not registered"): - mscale.unregister_scale('this_does_not_exist') + mscale.deregister_scale('this_does_not_exist') From 0081c8957d04790fbc8a015c137ee6c44073fb2a Mon Sep 17 00:00:00 2001 From: apple Date: Thu, 23 Apr 2026 22:43:31 +0530 Subject: [PATCH 10/16] Rename test functions to use deregister_scale --- lib/matplotlib/tests/test_scale.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index 0b51fb688311..40783f6a88c6 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -435,7 +435,7 @@ def test_val_in_range_base_fallback(): assert s.val_in_range(-np.inf) is False -def test_unregister_scale(): +def test_deregister_scale(): """Test that unregister_scale removes a scale correctly.""" # Register a temporary custom scale class TempScale(mscale.LinearScale): @@ -449,7 +449,7 @@ class TempScale(mscale.LinearScale): assert 'temp_test_scale' not in mscale._scale_mapping -def test_unregister_scale_invalid(): +def test_deregister_scale_invalid(): """Test that unregister_scale raises ValueError for unknown scale.""" with pytest.raises(ValueError, match="not registered"): mscale.deregister_scale('this_does_not_exist') From 8400592e1bccd4a520e86a66386d19ab809d7434 Mon Sep 17 00:00:00 2001 From: apple Date: Fri, 24 Apr 2026 03:58:16 +0530 Subject: [PATCH 11/16] Replace all unregister_scale with deregister_scale --- lib/matplotlib/tests/test_scale.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index 40783f6a88c6..78a7f3631a4b 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -330,7 +330,7 @@ def set_default_locators_and_formatters(self, axis): ax.set_xscale('custom') assert isinstance(ax.xaxis.get_transform(), CustomTransform) finally: - # cleanup - there's no public unregister_scale() + # cleanup - there's no public deregister_scale() del mscale._scale_mapping["custom"] del mscale._scale_has_axis_parameter["custom"] @@ -368,7 +368,7 @@ def set_default_locators_and_formatters(self, axis): ax.set_xscale('custom') assert isinstance(ax.xaxis.get_transform(), CustomTransform) finally: - # cleanup - there's no public unregister_scale() + # cleanup - there's no public deregister_scale() del mscale._scale_mapping["custom"] del mscale._scale_has_axis_parameter["custom"] @@ -436,7 +436,7 @@ def test_val_in_range_base_fallback(): def test_deregister_scale(): - """Test that unregister_scale removes a scale correctly.""" + """Test that deregister_scale removes a scale correctly.""" # Register a temporary custom scale class TempScale(mscale.LinearScale): name = 'temp_test_scale' @@ -450,6 +450,6 @@ class TempScale(mscale.LinearScale): def test_deregister_scale_invalid(): - """Test that unregister_scale raises ValueError for unknown scale.""" + """Test that deregister_scale raises ValueError for unknown scale.""" with pytest.raises(ValueError, match="not registered"): mscale.deregister_scale('this_does_not_exist') From b83f45ea3ecfe40abfc59a559cc6e61b26b377b5 Mon Sep 17 00:00:00 2001 From: apple Date: Fri, 24 Apr 2026 11:30:16 +0530 Subject: [PATCH 12/16] Use deregister_scale() in test cleanup --- lib/matplotlib/tests/test_scale.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index 78a7f3631a4b..d09bbb6100b8 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -331,8 +331,7 @@ def set_default_locators_and_formatters(self, axis): assert isinstance(ax.xaxis.get_transform(), CustomTransform) finally: # cleanup - there's no public deregister_scale() - del mscale._scale_mapping["custom"] - del mscale._scale_has_axis_parameter["custom"] + mscale.deregister_scale("custom") def test_custom_scale_with_axis(): From aaf5b7a4efb6aad452448bb35a0582bcd85106f5 Mon Sep 17 00:00:00 2001 From: apple Date: Sat, 25 Apr 2026 17:26:25 +0530 Subject: [PATCH 13/16] Remove outdated comment about deregister_scale --- lib/matplotlib/tests/test_scale.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index d09bbb6100b8..15ceec0736c7 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -330,7 +330,6 @@ def set_default_locators_and_formatters(self, axis): ax.set_xscale('custom') assert isinstance(ax.xaxis.get_transform(), CustomTransform) finally: - # cleanup - there's no public deregister_scale() mscale.deregister_scale("custom") @@ -367,7 +366,6 @@ def set_default_locators_and_formatters(self, axis): ax.set_xscale('custom') assert isinstance(ax.xaxis.get_transform(), CustomTransform) finally: - # cleanup - there's no public deregister_scale() del mscale._scale_mapping["custom"] del mscale._scale_has_axis_parameter["custom"] From 799bf8ee6e18cee52de4e1d515d09ee6943912ac Mon Sep 17 00:00:00 2001 From: apple Date: Sat, 25 Apr 2026 18:17:34 +0530 Subject: [PATCH 14/16] Fix TempScale using IdentityTransform --- lib/matplotlib/tests/test_scale.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index 15ceec0736c7..a0ae51ed5ff6 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -330,7 +330,9 @@ def set_default_locators_and_formatters(self, axis): ax.set_xscale('custom') assert isinstance(ax.xaxis.get_transform(), CustomTransform) finally: - mscale.deregister_scale("custom") + # cleanup - there's no public deregister_scale() + del mscale._scale_mapping["custom"] + del mscale._scale_has_axis_parameter["custom"] def test_custom_scale_with_axis(): @@ -366,6 +368,7 @@ def set_default_locators_and_formatters(self, axis): ax.set_xscale('custom') assert isinstance(ax.xaxis.get_transform(), CustomTransform) finally: + # cleanup - there's no public deregister_scale() del mscale._scale_mapping["custom"] del mscale._scale_has_axis_parameter["custom"] @@ -435,8 +438,16 @@ def test_val_in_range_base_fallback(): def test_deregister_scale(): """Test that deregister_scale removes a scale correctly.""" # Register a temporary custom scale - class TempScale(mscale.LinearScale): + class TempScale(mscale.ScaleBase): name = 'temp_test_scale' + + def get_transform(self): + from matplotlib.transforms import IdentityTransform + return IdentityTransform() + + def set_default_locators_and_formatters( + self, axis): + pass mscale.register_scale(TempScale) assert 'temp_test_scale' in mscale._scale_mapping From dc559da7d38a152704a7fe385f4202aa45398bdb Mon Sep 17 00:00:00 2001 From: apple Date: Sat, 25 Apr 2026 18:23:55 +0530 Subject: [PATCH 15/16] Fix Whitespace in blank lines --- lib/matplotlib/tests/test_scale.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index a0ae51ed5ff6..6341f6240418 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -440,11 +440,11 @@ def test_deregister_scale(): # Register a temporary custom scale class TempScale(mscale.ScaleBase): name = 'temp_test_scale' - + def get_transform(self): from matplotlib.transforms import IdentityTransform return IdentityTransform() - + def set_default_locators_and_formatters( self, axis): pass From 41ded341b627bb98505205b07b8b5cfcf32bfb3e Mon Sep 17 00:00:00 2001 From: apple Date: Sat, 25 Apr 2026 23:26:43 +0530 Subject: [PATCH 16/16] Remove outdated comments about no public deregister_scale() --- lib/matplotlib/tests/test_scale.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/tests/test_scale.py b/lib/matplotlib/tests/test_scale.py index 6341f6240418..6f0843411c8f 100644 --- a/lib/matplotlib/tests/test_scale.py +++ b/lib/matplotlib/tests/test_scale.py @@ -330,9 +330,7 @@ def set_default_locators_and_formatters(self, axis): ax.set_xscale('custom') assert isinstance(ax.xaxis.get_transform(), CustomTransform) finally: - # cleanup - there's no public deregister_scale() - del mscale._scale_mapping["custom"] - del mscale._scale_has_axis_parameter["custom"] + mscale.deregister_scale("custom") def test_custom_scale_with_axis(): @@ -368,9 +366,7 @@ def set_default_locators_and_formatters(self, axis): ax.set_xscale('custom') assert isinstance(ax.xaxis.get_transform(), CustomTransform) finally: - # cleanup - there's no public deregister_scale() - del mscale._scale_mapping["custom"] - del mscale._scale_has_axis_parameter["custom"] + mscale.deregister_scale("custom") def test_val_in_range(): @@ -441,6 +437,9 @@ def test_deregister_scale(): class TempScale(mscale.ScaleBase): name = 'temp_test_scale' + def __init__(self): + pass + def get_transform(self): from matplotlib.transforms import IdentityTransform return IdentityTransform()