Skip to content

Fix clabel manual index#31706

Merged
QuLogic merged 3 commits into
matplotlib:mainfrom
rahulrathnavel:fix-clabel-manual-index
Jun 10, 2026
Merged

Fix clabel manual index#31706
QuLogic merged 3 commits into
matplotlib:mainfrom
rahulrathnavel:fix-clabel-manual-index

Conversation

@rahulrathnavel

Copy link
Copy Markdown
Contributor

PR summary

closes #31702

This PR fixes a bug where using ax.clabel with the manual keyword raises an IndexError if 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, the add_label_near function was incorrectly using idx_level_min to access self.labelLevelList and self.labelCValueList. Because idx_level_min corresponds 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_min for the level variable, which correctly maps to the current subset being labeled. I also added a minimal pytest in test_contour.py that 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 minimal pytest function. 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

@timhoffm

Copy link
Copy Markdown
Member

@rahulrathnavel You have mixed commits for the clabel and violinplot issues. Please keep them in separate PRs.

@rahulrathnavel rahulrathnavel force-pushed the fix-clabel-manual-index branch from c4796aa to ce62b25 Compare May 19, 2026 13:35
@rahulrathnavel

rahulrathnavel commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

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.

@rcomer rcomer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/matplotlib/tests/test_contour.py Outdated
Comment thread lib/matplotlib/tests/test_contour.py Outdated
rahulrathnavel and others added 2 commits May 31, 2026 09:00
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
@rahulrathnavel

rahulrathnavel commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

@rcomer thanks for pointing out the unnecessary double import and that not useful comment 😅now i understood and will not repeat it.
i have committed the changes and that clears all checks as green/passed i believe and if anymore things need to be change suggest me.
Thanks! @timhoffm @rcomer

@rahulrathnavel

rahulrathnavel commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi @rcomer @timhoffm just checking in since this received an approval a few days ago,kindly let me know if there are any further changes needs to be done or if this is good to go. Happy to make any adjustments!😄

@rcomer

rcomer commented Jun 3, 2026

Copy link
Copy Markdown
Member

@rahulrathnavel for code changes we require approvals from two maintainers, so this is just waiting for someone else to find time to review it.

@rahulrathnavel

Copy link
Copy Markdown
Contributor Author

@rahulrathnavel for code changes we require two approvals from maintainers, so this is just waiting for someone else to find time to review it.

😅As i am new in here!i don't know that.
Now understood totally thanks!

@QuLogic QuLogic added this to the v3.11.0 milestone Jun 10, 2026
@QuLogic QuLogic merged commit 05d7a84 into matplotlib:main Jun 10, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: manual positioning fails for ax.clabel

4 participants