Skip to content

[Bug]: 3d mouse coords values reported in toolbar are meaningless #22775

Closed
@anntzer

Description

@anntzer

Bug summary

The mouse coords reported for 3D axes are meaningless (they correspond to some arbitrarily chosen depth). In fact, I do not believe there's any canonical way to choose the values displayed. See discussion starting at #22624 (comment).

Code for reproduction

# xyz values printed when dragging the mouse across window (default 3d view) horizontally,
# along the middle y position:
from pylab import *
from matplotlib.backend_bases import LocationEvent
rcdefaults(); rcParams["axes.unicode_minus"] = False  # use ascii minus
fig = figure()
ax = fig.add_subplot(projection="3d")
fig.canvas.draw()
xyzs = []
screen_ry = .5
# drag mouse across window horizontally, along the middle y position
for screen_rx in np.linspace(0, 1, 1001):
    screen_xy = fig.transFigure.transform((screen_rx, screen_ry))
    pseudo_xy = ax.transData.inverted().transform(screen_xy)
    ev = LocationEvent("", fig.canvas, *screen_xy)
    ev.xdata, ev.ydata = pseudo_xy
    if any([axis.pane.contains(ev)[0] for axis in ax._axis_map.values()]):
        s = ax.format_coord(*pseudo_xy)  # formatted string
        xyzs.append([float(part.split("=")[1]) for part in s.split(",")])  # displayed xyz
    else:  # out of Axes
        xyzs.append((np.nan, np.nan, np.nan))
xyzs = array(xyzs)
close(fig)
plot(xyzs[:, 0], label="x")
plot(xyzs[:, 1], label="y")
plot(xyzs[:, 2], label="z")
legend()
show()

Actual outcome

157819800-b2911b65-362e-49a7-bc9c-07039de3780a

Expected outcome

Don't try to display meaningless values.

Additional information

No response

Operating system

arch linux

Matplotlib Version

3.6.0.dev1926+gf670fe7879

Matplotlib Backend

mplcairo

Python version

3.10

Jupyter version

ENOSUCHLIB

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions