Skip to content

Unregister_scale() function to matplotlib.scale#31547

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

Unregister_scale() function to matplotlib.scale#31547
dikshajangra12918-oss wants to merge 12 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 and others added 2 commits April 23, 2026 05:10
@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,

assert isinstance(ax.xaxis.get_transform(), CustomTransform)
finally:
# cleanup - there's no public unregister_scale()
# cleanup - there's no public deregister_scale()
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.

Why not just use the method you just wrote?

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.

@story645,

Could you help me understand what exactly still needs to be fixed? I've updated the function name, tests, and stub file. The remaining failures seem to be pre-existing issues but I want to make sure I haven't missed anything on my end.

Any guidance would be really helpful!

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.

@dikshajangra12918-oss the test that you added is failing
https://github.com/matplotlib/matplotlib/actions/runs/24874799863/job/72828932746?pr=31547#step:13:179

You should also consider the logic of having a comment that states "there's no public deregister_scale" when that is the very function that you are adding.

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

3 participants