From a40ffaafe919d19ec93c7288202d8da99e42dae1 Mon Sep 17 00:00:00 2001 From: Scott Shambaugh Date: Mon, 31 Jul 2023 07:46:40 -0600 Subject: [PATCH] Call out which pane is hovered for 3d hover coordinates --- lib/mpl_toolkits/mplot3d/axes3d.py | 14 ++++++++++---- lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 10 +++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 3be3ba0c8920..13c58e256a39 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -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): @@ -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): """ diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index 671ce68b1e93..177ff25d7872 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -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():