Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5c0c15

Browse files
committed
Update find_nearest_contour to not use collections attribute
1 parent e394940 commit d5c0c15

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/matplotlib/contour.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,13 +1409,13 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True):
14091409
14101410
Returns
14111411
-------
1412-
contour : `.Collection`
1413-
The contour that is closest to ``(x, y)``.
1412+
path : int
1413+
The index of the path that is closest to ``(x, y)``.
14141414
segment : int
1415-
The index of the `.Path` in *contour* that is closest to
1415+
The index within that closest path of the segment that is closest to
14161416
``(x, y)``.
14171417
index : int
1418-
The index of the path segment in *segment* that is closest to
1418+
The index of the vertices within that segment that are closest to
14191419
``(x, y)``.
14201420
xmin, ymin : float
14211421
The point in the contour plot that is closest to ``(x, y)``.
@@ -1434,8 +1434,9 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True):
14341434
if self.filled:
14351435
raise ValueError("Method does not support filled contours.")
14361436

1437+
paths = self.get_paths()
14371438
if indices is None:
1438-
indices = range(len(self.collections))
1439+
indices = range(len(paths))
14391440

14401441
d2min = np.inf
14411442
conmin = None
@@ -1445,14 +1446,15 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True):
14451446
ymin = None
14461447

14471448
point = np.array([x, y])
1449+
trans = self.get_transform()
14481450

14491451
for icon in indices:
1450-
con = self.collections[icon]
1451-
trans = con.get_transform()
1452-
paths = con.get_paths()
1452+
path = paths[icon]
14531453

1454-
for segNum, linepath in enumerate(paths):
1454+
for segNum, linepath in enumerate(path._iter_connected_components()):
14551455
lc = linepath.vertices
1456+
if lc.size == 0:
1457+
continue
14561458
# transfer all data points to screen coordinates if desired
14571459
if pixel:
14581460
lc = trans.transform(lc)

0 commit comments

Comments
 (0)