FIX: fill contourf minimum region when it falls just below the lowest level (#21382)#31903
Open
SharadhNaidu wants to merge 1 commit into
Open
FIX: fill contourf minimum region when it falls just below the lowest level (#21382)#31903SharadhNaidu wants to merge 1 commit into
SharadhNaidu wants to merge 1 commit into
Conversation
… level (matplotlib#21382) contourf left the minimum-valued region unfilled when the data minimum fell a floating-point hair below the lowest contour level instead of being exactly equal to it (e.g. a computed -1.7e-13 where 0 was meant). ContourSet._get_lowers_and_uppers only extended the lowest filled interval down to the minimum when self.zmin == lowers[0] exactly, so such near-equal minima, or rounding during automatic level selection, slipped through and the region was clipped. On a linear scale, compare the level against the data minimum with a tolerance scaled to the data range rather than strict equality, the same way Colorbar._add_solids does. The check is one-sided and tolerance- bounded, so genuine gaps such as user-specified levels starting above the data are left untouched, and every case the old equality test caught still extends identically. Log scales span many decades where an additive tolerance is not meaningful, so the exact-equality test is kept there unchanged. Adds check_figures_equal regression tests that a float-noise minimum renders like a clean zero, including at very small and very large data scales, plus guard tests that a user-specified lowest level above the data is not back-filled, even when a large data range inflates the tolerance to order unity. Includes a behaviour-change note under doc/api/next_api_changes/.
4f525d1 to
d70e9b9
Compare
Member
Please don't do that; we want your description of what you did, and AI's writing is tiring to read. |
Contributor
Author
|
i am really sorry , i will make sure to not use AI for PR description in future , please give me some time , i will update the PR description . |
Contributor
Author
|
@QuLogic I am really sorry for the inconvenience , updated and ready. |
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.
Closes #21382.
PR summary
this PR fixes an annoying edge case where
contourfleaves the lowest contour region blank due to standard floating point right nowContourSet._get_lowers_and_uppersrequiresself.zminto exactly equal the lowest level meaning a computed minimum that's just a tiny margin like -1.7e-13 instead of 0 gets clipped instead of drawnto fix this i replaced the exact == check with a tolerance scaled to the data range i only applied this to linear scales as log scales cover way too many orders of magnitude for an additive tolerance to mean anything the new check is one sided ensuring that deliberate gaps like user passed levels starting above the data are perfectly preserved while quietly catching the rounding errors the old check used to miss
I used AI to help me understand parts of the codebase in the contour code part . The code changes and design decisions were developed independently.
Testing
Added a
check_figures_equaltest that a float-noise minimum draws the same as a clean zero (including at very small and very large data scales), plus guard tests so a user-specified lowest level above the data doesn't get back-filled even when a big data range inflates the tolerance.PR checklist