Skip to content

Fix clabel manual index#31706

Open
rahulrathnavel wants to merge 1 commit into
matplotlib:mainfrom
rahulrathnavel:fix-clabel-manual-index
Open

Fix clabel manual index#31706
rahulrathnavel wants to merge 1 commit into
matplotlib:mainfrom
rahulrathnavel:fix-clabel-manual-index

Conversation

@rahulrathnavel
Copy link
Copy Markdown

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
Copy link
Copy Markdown
Author

rahulrathnavel commented May 19, 2026

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.

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

2 participants