Skip to content

Commit a48e425

Browse files
committed
Omit MOVETO lines from nearest contour logic
Closes #27333
1 parent b16031c commit a48e425

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/matplotlib/contour.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,15 +1339,18 @@ def _find_nearest_contour(self, xy, indices=None):
13391339

13401340
for idx_level in indices:
13411341
path = self._paths[idx_level]
1342-
if not len(path.vertices):
1343-
continue
1344-
lc = self.get_transform().transform(path.vertices)
1345-
d2, proj, leg = _find_closest_point_on_path(lc, xy)
1346-
if d2 < d2min:
1347-
d2min = d2
1348-
idx_level_min = idx_level
1349-
idx_vtx_min = leg[1]
1350-
proj_min = proj
1342+
idx_vtx_start = 0
1343+
for subpath in path._iter_connected_components():
1344+
if not len(subpath.vertices):
1345+
continue
1346+
lc = self.get_transform().transform(subpath.vertices)
1347+
d2, proj, leg = _find_closest_point_on_path(lc, xy)
1348+
if d2 < d2min:
1349+
d2min = d2
1350+
idx_level_min = idx_level
1351+
idx_vtx_min = leg[1] + idx_vtx_start
1352+
proj_min = proj
1353+
idx_vtx_start += len(subpath)
13511354

13521355
return idx_level_min, idx_vtx_min, proj_min
13531356

0 commit comments

Comments
 (0)