Fix matplotlib >= 3.8 AttributeError in show_factorization_on_image#577
Open
Pchambet wants to merge 1 commit intojacobgil:masterfrom
Open
Fix matplotlib >= 3.8 AttributeError in show_factorization_on_image#577Pchambet wants to merge 1 commit intojacobgil:masterfrom
Pchambet wants to merge 1 commit intojacobgil:masterfrom
Conversation
Replace deprecated `FigureCanvasAgg.tostring_rgb()` with `FigureCanvasAgg.buffer_rgba()`. `tostring_rgb()` was deprecated in matplotlib 3.8 and removed in 3.10, causing an `AttributeError` when calling `show_factorization_on_image`. The new `buffer_rgba()` returns a shaped RGBA array directly, so the manual `reshape` call is no longer needed. The alpha channel is sliced off with `[..., :3]`, and `.copy()` ensures the data is independent of the canvas buffer before the figure is closed. Fixes jacobgil#556
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.
Problem
show_factorization_on_imageraises anAttributeErrorwith matplotlib >= 3.8:FigureCanvasAgg.tostring_rgb()was deprecated in matplotlib 3.8 and removed in 3.10.Fix
Replace
tostring_rgb()withbuffer_rgba(), which is the recommended successor:Why this works
tostring_rgb()(old)buffer_rgba()(new)bytesmemoryview(H × W × 4)frombuffer+reshape)Since
buffer_rgba()returns a properly shaped RGBA array, we:[..., :3]to get RGB.copy()to detach from the canvas buffer beforeplt.close()frees itreshapecallBackward compatibility
buffer_rgba()has been available since matplotlib 3.1, so this change is backward-compatible with any matplotlib version that this library reasonably supports.Fixes #556