-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: find_nearest_contour deprecated with no replacement? #27070
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
Comments
It was deprecated because the old return value (Collection (=level), index of Path in Collection (=index of connected component at that level), index of segment in Path, x, y, distance) doesn't really make much sense for the new internal representation of ContourSets (there's a single Collection, and a single path per level). |
https://stackoverflow.com/questions/77281818/find-nearest-contour-is-deprecated-now-what I don't personally need "nearest contour" but you can imagine it would be very useful to people. I imagine the poster's use case would be met by some public equivalent... |
Let's just make _find_nearest_contour public under a different name. |
@jklymak thanks for sharing my question on Stack Overflow. I have code that depends on this functionality, and deprecations make me nervous :) |
@anntzer actually, To give you context, I'm using Matplotlib contours to explore a 2d map. I'm using
The point is that there are multiple contours created at |
I now realize that also |
@matteobachetti the previous |
Ah, looking at this again I missed the fact that the first tuple item returned by find_nearest_contour is not a Collection (despite what the docstring says), but the index of the collection (effectively the level index). |
From a quick look, the old find_nearest_contour can be implemented in terms of the new one as follows (modulo off-by-one errors): from contextlib import ExitStack
...
def find_nearest_contour(...):
with ExitStack() as stack:
if not pixel:
stack.enter_context(self._cm_set(
transform=mtransforms.IdentityTransform()))
i_level, i_vtx, (xmin, ymin) = self._find_nearest_contour((x, y), indices)
cc_cumlens = np.cumsum(
[*map(len, self._paths[i_level]._iter_connected_components())])
segment = cc_cumlens.searchsorted(i_vtx, "right") - 1
index = i_vtx - cc_cumlens[segment]
return (i_level, segment, index, xmin, ymin, (xmin-x)**2 + (ymin-y)**2) |
Bug summary
In #25247 we deprecated
find_nearest_contour
with no replacement or mention in the release notes. Why was this deprecated, and what is the replacement? ping @anntzer @ianthomas23https://github.com/matplotlib/matplotlib/blob/c06a97e84b8424a87d0e294c5eaf406a1f8d0a62/lib/matplotlib/contour.py#L1391C5-L1392C68
The text was updated successfully, but these errors were encountered: