Find the point in the unfilled contour plot that is closest (in screen space) to point *xy*. Parameters ---------- xy : tuple[float, float] The reference point (in screen space). indices : list of int or None, default: None In
(self, xy, indices=None)
| 1175 | return tlinestyles |
| 1176 | |
| 1177 | def _find_nearest_contour(self, xy, indices=None): |
| 1178 | """ |
| 1179 | Find the point in the unfilled contour plot that is closest (in screen |
| 1180 | space) to point *xy*. |
| 1181 | |
| 1182 | Parameters |
| 1183 | ---------- |
| 1184 | xy : tuple[float, float] |
| 1185 | The reference point (in screen space). |
| 1186 | indices : list of int or None, default: None |
| 1187 | Indices of contour levels to consider. If None (the default), all levels |
| 1188 | are considered. |
| 1189 | |
| 1190 | Returns |
| 1191 | ------- |
| 1192 | idx_level_min : int |
| 1193 | The index of the contour level closest to *xy*. |
| 1194 | idx_vtx_min : int |
| 1195 | The index of the `.Path` segment closest to *xy* (at that level). |
| 1196 | proj : (float, float) |
| 1197 | The point in the contour plot closest to *xy*. |
| 1198 | """ |
| 1199 | |
| 1200 | # Convert each contour segment to pixel coordinates and then compare the given |
| 1201 | # point to those coordinates for each contour. This is fast enough in normal |
| 1202 | # cases, but speedups may be possible. |
| 1203 | |
| 1204 | if self.filled: |
| 1205 | raise ValueError("Method does not support filled contours") |
| 1206 | |
| 1207 | if indices is None: |
| 1208 | indices = range(len(self._paths)) |
| 1209 | |
| 1210 | d2min = np.inf |
| 1211 | idx_level_min = idx_vtx_min = proj_min = None |
| 1212 | |
| 1213 | for idx_level in indices: |
| 1214 | path = self._paths[idx_level] |
| 1215 | idx_vtx_start = 0 |
| 1216 | for subpath in path._iter_connected_components(): |
| 1217 | if not len(subpath.vertices): |
| 1218 | continue |
| 1219 | lc = self.get_transform().transform(subpath.vertices) |
| 1220 | d2, proj, leg = _find_closest_point_on_path(lc, xy) |
| 1221 | if d2 < d2min: |
| 1222 | d2min = d2 |
| 1223 | idx_level_min = idx_level |
| 1224 | idx_vtx_min = leg[1] + idx_vtx_start |
| 1225 | proj_min = proj |
| 1226 | idx_vtx_start += len(subpath) |
| 1227 | |
| 1228 | return idx_level_min, idx_vtx_min, proj_min |
| 1229 | |
| 1230 | def find_nearest_contour(self, x, y, indices=None, pixel=True): |
| 1231 | """ |
no test coverage detected