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

Skip to content

Unregister_scale() function to matplotlib.scale#31547

Open
dikshajangra12918-oss wants to merge 10 commits intomatplotlib:mainfrom
dikshajangra12918-oss:add-unregister-scale
Open

Unregister_scale() function to matplotlib.scale#31547
dikshajangra12918-oss wants to merge 10 commits intomatplotlib:mainfrom
dikshajangra12918-oss:add-unregister-scale

Conversation

@dikshajangra12918-oss
Copy link
Copy Markdown
Contributor

PR Summary

Currently matplotlib has register_scale() but no way to remove a registered scale. This is a problem when a custom scale is created for just one plot — there is no way to clean up after that plot is drawn.

This PR adds unregister_scale(name) to fix that gap. Uses pop() for idiomatic dict cleanup.

Changes made:
~ Added unregister_scale() in lib/matplotlib/scale.py
~ Raises ValueError if scale name is not registered
~ Added tests in lib/matplotlib/tests/test_scale.py

Closes #5791

AI Disclosure

I used Claude (AI) for guidance on implementation approach. Code was written and verified by me.

PR Checklist

~ [x] Closes #5791 is in the PR description
~ [x] New code is tested

dikshajangra12918-oss and others added 3 commits April 21, 2026 15:25
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.
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.
@dikshajangra12918-oss dikshajangra12918-oss marked this pull request as ready for review April 22, 2026 18:05
Comment thread lib/matplotlib/scale.py Outdated
@dikshajangra12918-oss
Copy link
Copy Markdown
Contributor Author

@story645,

The remaining failures are pre-existing issues with Qt backends and are unrelated to this PR.
All checks related to our changes are passing!

Comment thread lib/matplotlib/tests/test_scale.py Outdated
assert 'temp_test_scale' not in mscale._scale_mapping


def test_unregister_scale_invalid():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deregister

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @story645!

I've updated the function and test names to use deregister_scale. Please taek a look.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still didn't catch everything,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No way to unregister a custom scale

2 participants