FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: 3d mouse coords values reported in toolbar are meaningless · Issue #22775 · matplotlib/matplotlib · GitHub

Repository navigation

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

Closed

Description

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

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

Activity

  1. added this to the v3.7.0 milestone on Apr 4, 2022
  2. nhansendev commented on Jul 2, 2022

    Contributor

    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".

  3. scottshambaugh commented on Jul 18, 2022

    Contributor

    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.

  4. modified the milestones: future releases, v3.8.0 on Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL