I'm using Matplotlib contours to explore a 2d map. I'm using contour.find_nearest_contour to get the range of x and y of the contour that passes close to a point x0, y0, as follows:
cs = fig.gca().contour(x, y, image, [level])
cont, seg, idx, xm, ym, d2 = cs.find_nearest_contour(x0, y0, pixel=False)
min_x = cs.allsegs[cont][seg][:, 0].min()
max_x = cs.allsegs[cont][seg][:, 0].max()
min_y = cs.allsegs[cont][seg][:, 1].min()
max_y = cs.allsegs[cont][seg][:, 1].max()
cont, seg, idx, xm, ym, d2 = cs.find_nearest_contour(x0, y0, pixel=False)
Now Matplotlib v3.8 is throwing a MatplotlibDeprecationWarning, but I can't find any document that explains how to get the same functionality.
Note that a given contour level can create multiple segments, and I also need what segment is closer to my point. I need seg in my line of code, practically. This is not shared from the private method _find_nearest_contour which was a very good candidate for replacement.
.find_nearest_contouruntil it's removed.._find_nearest_contour, can be used until, or if, a public method is reimplemented.ReturnsCS.find_nearest_contour(0, 0)→(5, 0, 296, 209.70308429471964, 168.30113207547168, 72300.65462060366)CS._find_nearest_contour((0, 0))→(5, 296, array([209.70308429, 168.30113208]))Regarding Private Methods