Skip to content

Commit 60b3f54

Browse files
authored
Merge pull request #16195 from anntzer/find_nearest_contour
Numpydoc ContourSet.find_nearest_contour.
2 parents e154a0d + 989b2b7 commit 60b3f54

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

lib/matplotlib/contour.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -1297,24 +1297,34 @@ def set_alpha(self, alpha):
12971297

12981298
def find_nearest_contour(self, x, y, indices=None, pixel=True):
12991299
"""
1300-
Finds contour that is closest to a point. Defaults to
1301-
measuring distance in pixels (screen space - useful for manual
1302-
contour labeling), but this can be controlled via a keyword
1303-
argument.
1300+
Find the point in the contour plot that is closest to ``(x, y)``.
13041301
1305-
Returns a tuple containing the contour, segment, index of
1306-
segment, x & y of segment point and distance to minimum point.
1307-
1308-
Optional keyword arguments:
1309-
1310-
*indices*:
1311-
Indexes of contour levels to consider when looking for
1312-
nearest point. Defaults to using all levels.
1313-
1314-
*pixel*:
1315-
If *True*, measure distance in pixel space, if not, measure
1316-
distance in axes space. Defaults to *True*.
1302+
Parameters
1303+
----------
1304+
x, y: float
1305+
The reference point.
1306+
indices : list of int or None, default: None
1307+
Indices of contour levels to consider. If None (the default), all
1308+
levels are considered.
1309+
pixel : bool, default: True
1310+
If *True*, measure distance in pixel (screen) space, which is
1311+
useful for manual contour labeling; else, measure distance in axes
1312+
space.
13171313
1314+
Returns
1315+
-------
1316+
contour : `.Collection`
1317+
The contour that is closest to ``(x, y)``.
1318+
segment : int
1319+
The index of the `.Path` in *contour* that is closest to
1320+
``(x, y)``.
1321+
index : int
1322+
The index of the path segment in *segment* that is closest to
1323+
``(x, y)``.
1324+
xmin, ymin : float
1325+
The point in the contour plot that is closest to ``(x, y)``.
1326+
d : float
1327+
The distance from ``(xmin, ymin)`` to ``(x, y)``.
13181328
"""
13191329

13201330
# This function uses a method that is probably quite

0 commit comments

Comments
 (0)