Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b1508f

Browse files
authored
Merge pull request #26433 from scottshambaugh/3d_coords_pane
Call out which pane is hovered over for 3d hover coordinates
2 parents a92b784 + a40ffaa commit 4b1508f

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,11 +1096,16 @@ def _location_coords(self, xv, yv, renderer):
10961096
"""
10971097
Return the location on the axis pane underneath the cursor as a string.
10981098
"""
1099-
p1 = self._calc_coord(xv, yv, renderer)
1099+
p1, pane_idx = self._calc_coord(xv, yv, renderer)
11001100
xs = self.format_xdata(p1[0])
11011101
ys = self.format_ydata(p1[1])
11021102
zs = self.format_zdata(p1[2])
1103-
coords = f'x={xs}, y={ys}, z={zs}'
1103+
if pane_idx == 0:
1104+
coords = f'x pane={xs}, y={ys}, z={zs}'
1105+
elif pane_idx == 1:
1106+
coords = f'x={xs}, y pane={ys}, z={zs}'
1107+
elif pane_idx == 2:
1108+
coords = f'x={xs}, y={ys}, z pane={zs}'
11041109
return coords
11051110

11061111
def _get_camera_loc(self):
@@ -1148,11 +1153,12 @@ def _calc_coord(self, xv, yv, renderer=None):
11481153
scales[i] = np.inf
11491154
else:
11501155
scales[i] = (p1[i] - pane_locs[i]) / vec[i]
1151-
scale = scales[np.argmin(abs(scales))]
1156+
pane_idx = np.argmin(abs(scales))
1157+
scale = scales[pane_idx]
11521158

11531159
# Calculate the point on the closest pane
11541160
p2 = p1 - scale*vec
1155-
return p2
1161+
return p2, pane_idx
11561162

11571163
def _on_move(self, event):
11581164
"""

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,27 +1932,27 @@ def test_format_coord():
19321932
xv = 0.1
19331933
yv = 0.1
19341934
fig.canvas.draw()
1935-
assert ax.format_coord(xv, yv) == 'x=10.5227, y=1.0417, z=0.1444'
1935+
assert ax.format_coord(xv, yv) == 'x=10.5227, y pane=1.0417, z=0.1444'
19361936

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

19421942
# Reset parameters
19431943
ax.view_init()
19441944
fig.canvas.draw()
1945-
assert ax.format_coord(xv, yv) == 'x=10.5227, y=1.0417, z=0.1444'
1945+
assert ax.format_coord(xv, yv) == 'x=10.5227, y pane=1.0417, z=0.1444'
19461946

19471947
# Check orthographic projection
19481948
ax.set_proj_type('ortho')
19491949
fig.canvas.draw()
1950-
assert ax.format_coord(xv, yv) == 'x=10.8869, y=1.0417, z=0.1528'
1950+
assert ax.format_coord(xv, yv) == 'x=10.8869, y pane=1.0417, z=0.1528'
19511951

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

19571957

19581958
def test_get_axis_position():

0 commit comments

Comments
 (0)