Skip to content

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

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

Closed
anntzer opened this issue Apr 3, 2022 · 2 comments · Fixed by #23485
Closed

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

anntzer opened this issue Apr 3, 2022 · 2 comments · Fixed by #23485
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented Apr 3, 2022

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

@tacaswell tacaswell added this to the v3.7.0 milestone Apr 4, 2022
@nhansendev
Copy link
Contributor

nhansendev commented Jul 2, 2022

Out of curiosity I'm trying to determine what the expected behavior is.

In the case where there is no datapoint/line/surface under the cursor then it would make sense to project the mouse location directly onto the plane under the cursor. This would result in one axis always returning zero, is cheap to do, and intuitively makes sense.

If a point does exist within some margin of error to the current cursor location, then its X, Y, and Z coordinates could be retrieved. However, this could be expensive to do since (depending on what assumptions can be made) for very large datasets we may have to calculate the distance to every point to find the closest, and recalculate constantly as the mouse moves. What level of approximation is possible/acceptable?

A different problem arises for lines and surfaces. Do we expect interpolation between datapoints?

Additionally, even if the X, Y, and Z coordinates were to be made "accurate", how do we know that an item in 3D space is correctly being referenced? If five datapoints are under the cursor at varying depths will the shallowest always be selected? It may help to display the name of the dataset that the point is from using the legend, if available.

How does this compare to what is being done currently?

Getting accurate results sounds very non-trivial, but certainly useful.
I agree that the arbitrary depth that is currently being used is misleading. Even with a simple plot containing one point (or no points at all) the reported values vary while following a grid line depending on your "depth".

@scottshambaugh
Copy link
Contributor

scottshambaugh commented Jul 18, 2022

In the case where there is no datapoint/line/surface under the cursor then it would make sense to project the mouse location directly onto the plane under the cursor. This would result in one axis always returning zero, is cheap to do, and intuitively makes sense.

I think this is the only solution that makes sense right now. Hovering over 2D plots doesn't snap to coordinates right now, and I think something like that would be required to do what @Obliman is suggesting (which would be a nice end state, just a lot of groundwork that would need to be laid first). I do think displaying these is still useful to have, contra some of the discussion in the linked post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants