Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Issue with find_nearest_contour in contour.py #22762

Closed
jhelmboldt opened this issue Apr 1, 2022 · 3 comments · Fixed by #22767
Closed

[Bug]: Issue with find_nearest_contour in contour.py #22762

jhelmboldt opened this issue Apr 1, 2022 · 3 comments · Fixed by #22767
Labels
status: has patch patch suggested, PR still needed
Milestone

Comments

@jhelmboldt
Copy link

Bug summary

The default for the indices keyword in the find_nearest_contour function within countour.py is defined incorrectly in the code. Line 1377 should be "indices = range(len(self.layers))" instead of "indices = range(len(self.levels))."

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
xy=np.indices((100,100))
img=np.exp(-np.pi*(np.sum((xy-50)**2,0)/20.**2))
cs=plt.contourf(img,50)
cs.find_nearest_contour(20,20,pixel=False)

Actual outcome

Traceback (most recent call last):
File "", line 1, in
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/matplotlib/contour.py", line 1388, in find_nearest_contour
con = self.collections[icon]
IndexError: list index out of range

Expected outcome

(0, 0, 397, 23.68976612821045, 14.034856810732212, 49.197307349357025)

Additional information

No response

Operating system

Mac OS 12.3.1

Matplotlib Version

3.5.1

Matplotlib Backend

TkAgg

Python version

3.8.12

Jupyter version

No response

Installation

pip

@tacaswell tacaswell added this to the v3.5.2 milestone Apr 1, 2022
@tacaswell tacaswell added the status: has patch patch suggested, PR still needed label Apr 1, 2022
@tacaswell
Copy link
Member

@jhelmboldt Would you be willing to open a PR with that change + a test?

@andrew-fennell
Copy link
Contributor

If @jhelmboldt does not want to open a PR, I can make one later today.

@jhelmboldt
Copy link
Author

Thanks, @andrew-fennell. I've never submitted a PR before and don't have time to learn today, so I would appreciate you handling it. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: has patch patch suggested, PR still needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants