Fix: Prevent clabel() from modifying filled contour geometry#31348
Fix: Prevent clabel() from modifying filled contour geometry#31348shivamrajsr07 wants to merge 1 commit intomatplotlib:mainfrom
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on gitter for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
Skipping the path breaking is indeed simple. However, the problem plot also wrongly shows two numbers on each boundary, and that is much harder to fix. As noted already in the issue comments and the existing PR, this was never expected to work for filled contours. So I’m sorry but I’m going to close this. |
Summary
Fixes an issue where adding contour labels using
clabel()on filled contour plots (contourf) alters the geometry of the filled regions.When inline labeling is enabled, the labeling logic modifies internal path data. This behavior is appropriate for line contours but unintentionally affects filled contours, resulting in distorted shapes.
Root Cause
The inline labeling code updates the internal
_pathsof the contour set regardless of whether the contour is filled or not. For filled contours, these paths define the filled regions themselves, so modifying them changes the visual output.Fix
Restrict path modification to non-filled contours only. Inline labeling now avoids mutating
_pathswhenself.filledis True.Reproduction
Example demonstrating the issue: