mpldatacursor icon indicating copy to clipboard operation
mpldatacursor copied to clipboard

AttributeError: module 'mpl_toolkits.mplot3d.proj3d' has no attribute 'line2d_seg_dist'

Open fangwancong opened this issue 3 years ago • 0 comments

I got an error "AttributeError: module 'mpl_toolkits.mplot3d.proj3d' has no attribute 'line2d_seg_dist'" when running on the matplotlib 3.4.2, it is a deprecated method. Is there an update for this? I added the line2d_seg_dist method to the pick_info.py file to replace it, and it is feasible for the time being. def line2d_seg_dist(p1, p2, p0): """distance(s) from line defined by p1 - p2 to point(s) p0

p0[0] = x(s)
p0[1] = y(s)

intersection point p = p1 + u*(p2-p1)
and intersection point lies within segment if u is between 0 and 1
"""

x21 = p2[0] - p1[0]
y21 = p2[1] - p1[1]
x01 = np.asarray(p0[0]) - p1[0]
y01 = np.asarray(p0[1]) - p1[1]

u = (x01*x21 + y01*y21) / (x21**2 + y21**2)
u = np.clip(u, 0, 1)
d = np.hypot(x01 - u*x21, y01 - u*y21)

return d

fangwancong avatar Jul 19 '21 06:07 fangwancong