Skip to content

[Bug]: ContourLabeler.clabel with manual != False breaks unconnected contours #27062

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

Closed
rho-novatron opened this issue Oct 11, 2023 · 5 comments · Fixed by #27045
Closed

[Bug]: ContourLabeler.clabel with manual != False breaks unconnected contours #27062

rho-novatron opened this issue Oct 11, 2023 · 5 comments · Fixed by #27045
Milestone

Comments

@rho-novatron
Copy link

rho-novatron commented Oct 11, 2023

Bug summary

When adding contour label positions manually (either via clicking or specifying an iterable of positions), contours with disconnected parts are not handled correctly, but sometimes rejoined seemingly arbitrarily.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
x, y = np.mgrid[-1:1:21j, -1:1:21j]

cs = ax.contour(x, y, 1/np.sqrt(0.01+(x+0.3)**2+y**2) + 1/np.sqrt(0.01+(x-0.3)**2+y**2), levels=[7])
cs.clabel(manual=[(0.2, 0.1)])

Actual outcome

image

Expected outcome

As it looked in matplotlib 3.7.3:
image

Additional information

No response

Operating system

No response

Matplotlib Version

3.8.0

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

conda

@jklymak
Copy link
Member

jklymak commented Oct 11, 2023

Did this break, or did it never work?

@rho-novatron
Copy link
Author

rho-novatron commented Oct 11, 2023

It looks correct in 3.7.3. I updated the "expected outcome" screenshot from that.

@rho-novatron
Copy link
Author

It is also still broken in main now (6501209 )

@ksunden
Copy link
Member

ksunden commented Oct 11, 2023

I was able to fix this with a one line change, there was a line that struck me as possibly wrong when looking into #26971, but it was not related to that one, and was instead related to this bug. I'll add it to #27045

ksunden added a commit to ksunden/matplotlib that referenced this issue Oct 11, 2023
Closes matplotlib#27062

The code for rotation had referred to the original path, when it should
only be rotating the connected segment, which had already been
extracted.
@rho-novatron
Copy link
Author

Yay - the one-liner works for me. Thanks!

@QuLogic QuLogic added this to the v3.8.1 milestone Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants