Skip to content

Call out which pane is hovered over for 3d hover coordinates #26433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,11 +1096,16 @@ def _location_coords(self, xv, yv, renderer):
"""
Return the location on the axis pane underneath the cursor as a string.
"""
p1 = self._calc_coord(xv, yv, renderer)
p1, pane_idx = self._calc_coord(xv, yv, renderer)
xs = self.format_xdata(p1[0])
ys = self.format_ydata(p1[1])
zs = self.format_zdata(p1[2])
coords = f'x={xs}, y={ys}, z={zs}'
if pane_idx == 0:
coords = f'x pane={xs}, y={ys}, z={zs}'
elif pane_idx == 1:
coords = f'x={xs}, y pane={ys}, z={zs}'
elif pane_idx == 2:
coords = f'x={xs}, y={ys}, z pane={zs}'
return coords

def _get_camera_loc(self):
Expand Down Expand Up @@ -1148,11 +1153,12 @@ def _calc_coord(self, xv, yv, renderer=None):
scales[i] = np.inf
else:
scales[i] = (p1[i] - pane_locs[i]) / vec[i]
scale = scales[np.argmin(abs(scales))]
pane_idx = np.argmin(abs(scales))
scale = scales[pane_idx]

# Calculate the point on the closest pane
p2 = p1 - scale*vec
return p2
return p2, pane_idx

def _on_move(self, event):
"""
Expand Down
10 changes: 5 additions & 5 deletions lib/mpl_toolkits/mplot3d/tests/test_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,27 +1932,27 @@ def test_format_coord():
xv = 0.1
yv = 0.1
fig.canvas.draw()
assert ax.format_coord(xv, yv) == 'x=10.5227, y=1.0417, z=0.1444'
assert ax.format_coord(xv, yv) == 'x=10.5227, y pane=1.0417, z=0.1444'

# Modify parameters
ax.view_init(roll=30, vertical_axis="y")
fig.canvas.draw()
assert ax.format_coord(xv, yv) == 'x=9.1875, y=0.9761, z=0.1291'
assert ax.format_coord(xv, yv) == 'x pane=9.1875, y=0.9761, z=0.1291'

# Reset parameters
ax.view_init()
fig.canvas.draw()
assert ax.format_coord(xv, yv) == 'x=10.5227, y=1.0417, z=0.1444'
assert ax.format_coord(xv, yv) == 'x=10.5227, y pane=1.0417, z=0.1444'

# Check orthographic projection
ax.set_proj_type('ortho')
fig.canvas.draw()
assert ax.format_coord(xv, yv) == 'x=10.8869, y=1.0417, z=0.1528'
assert ax.format_coord(xv, yv) == 'x=10.8869, y pane=1.0417, z=0.1528'

# Check non-default perspective projection
ax.set_proj_type('persp', focal_length=0.1)
fig.canvas.draw()
assert ax.format_coord(xv, yv) == 'x=9.0620, y=1.0417, z=0.1110'
assert ax.format_coord(xv, yv) == 'x=9.0620, y pane=1.0417, z=0.1110'


def test_get_axis_position():
Expand Down