Fix: Compatibility with newer Matplotlib versions (handles MatplotlibDeprecationWarning) - #43
Open
andrebadini wants to merge 2 commits into
Open
Fix: Compatibility with newer Matplotlib versions (handles MatplotlibDeprecationWarning)#43andrebadini wants to merge 2 commits into
andrebadini wants to merge 2 commits into
Conversation
Fix: Handle MatplotlibDeprecationWarning for compatibility with newer Matplotlib versions The `MatplotlibDeprecationWarning` has been removed or renamed in recent versions of Matplotlib, causing an `AttributeError` when `july` is used with those versions. This commit modifies the `update_rcparams` function in `rcmod.py` to use a more robust approach to filtering warnings. It attempts to filter `MatplotlibDeprecationWarning` for compatibility with older Matplotlib versions and falls back to filtering the more general `DeprecationWarning` if the former is not available. This ensures compatibility with a wider range of Matplotlib versions.
flokli
added a commit
to flokli/july
that referenced
this pull request
Apr 28, 2025
This code was responsible from hiding deprecation warnings if a key gets unused, but it causes more harm than good: mpl did refactor their deprecation system, and the code simply failed as the old mpl.cbook.MatplotlibDeprecationWarning didn't exist anymore. Instead of going the approach of e-hulten#39 or e-hulten#43 again and adjusting to the change, simply drop the deprecation warning hiding alltogether. It'll show when july starts using deprecated keys, so they can be updated. Also use `mpl.rcParams[key] = value` directly and drop the ConfigDict logic, as it's unneeded. Closes e-hulten#39. Closes e-hulten#43.
|
Alternative approach: #44 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request addresses an
AttributeErrorthat occurs when usingjulywith recent versions of Matplotlib. The error is caused by the removal or renaming ofMatplotlibDeprecationWarningin Matplotlib.The fix implemented in this PR modifies the
update_rcparamsfunction inrcmod.pyto handle the absence ofMatplotlibDeprecationWarninggracefully. It now attempts to filterMatplotlibDeprecationWarningand, if that fails (due to the attribute not being present), it falls back to filteringDeprecationWarning. This approach ensures that the code works correctly with both older and newer Matplotlib releases.This change should resolve issues where users encounter the following error:
AttributeError: module 'matplotlib.cbook' has no attribute 'MatplotlibDeprecationWarning'. Did you mean: 'VisibleDeprecationWarning'?