Fix clabel manual index#31706
Conversation
c4796aa to
ce62b25
Compare
|
Hi @timhoffm, I've successfully force-pushed and completely separated the commits! This PR now strictly contains only the clabel fix. It looks like all the CI checks are passing perfectly now (as you suggested me-with the exception of the appveyor/pr Windows workflow, which seems to be the same upstream micromamba infrastructure error affecting other PRs right now). Please let me know if the code looks good to go or if you need any adjustments from my end! Thanks again for the guidance. |
There was a problem hiding this comment.
Thanks @rahulrathnavel this looks right to me, though I admit it took me a while to get my head around the logic! Just one unnecessary import and one unnecessary comment to remove I think.
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
|
@rahulrathnavel for code changes we require approvals from two maintainers, so this is just waiting for someone else to find time to review it. |
…706-on-v3.11.x Backport PR #31706 on branch v3.11.x (Fix clabel manual index)

PR summary
closes #31702
This PR fixes a bug where using
ax.clabelwith themanualkeyword raises anIndexErrorif the user specifies a subset of contour levels (fewer than the total available in the contour set).What problem does it solve and reasoning:
In
lib/matplotlib/contour.py, theadd_label_nearfunction was incorrectly usingidx_level_minto accessself.labelLevelListandself.labelCValueList. Becauseidx_level_mincorresponds to the index of the entire contour set, passing a filtered subset of levels caused it to search out-of-bounds.As suggested by the original issue author, I swapped
idx_level_minfor thelevelvariable, which correctly maps to the current subset being labeled. I also added a minimal pytest intest_contour.pythat verifies a manual label can be placed on a subset contour without throwing an exception.AI Disclosure
I used an AI assistant strictly to help navigate the repository structure, locate the specific lines in
contour.py, and draft the boilerplate for the minimalpytestfunction. The core logic fix was suggested by the issue author, and I manually applied, reviewed, and tested the changes locally to ensure complete Matplotlib compliance.PR checklist