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

Skip to content

How do I get the point coordinates (xyz) on a 3d graph? #16156

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
Daemon1992 opened this issue Jan 8, 2020 · 5 comments
Closed

How do I get the point coordinates (xyz) on a 3d graph? #16156

Daemon1992 opened this issue Jan 8, 2020 · 5 comments
Labels
Community support Users in need of help.

Comments

@Daemon1992
Copy link

Daemon1992 commented Jan 8, 2020

Bug report

Bug summary
I've created a three-dimensional line graph, and I want to click on a point in the graph, and there's a response event.The matplotlib example doesn't seem to support 3d event response very well.
I can't get the right z coordinate of the selected point..

Code for reproduction

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
from matplotlib.patches import Rectangle
import numpy as np
from numpy.random import rand
np.random.seed(19680801)

def eventHandleSet():
    print("eventHandle set")
    def onpick1(event):
        ind = event.ind
        print("clikced point index : ",xs[ind],ys[ind],zs[ind])
        if isinstance(event.artist, Line2D):
            thisline = event.artist
            xdata = thisline.get_xdata()
            ydata = thisline.get_ydata()
            ind = event.ind
            print('onpick1 line:', np.column_stack([xdata[ind], ydata[ind]]))
        elif isinstance(event.artist, Rectangle):
            patch = event.artist
            print('onpick1 patch:', patch.get_path())
    fig.canvas.mpl_connect('pick_event', onpick1)

    # def onclick(event):
    #     print('%s click: button=%d, x=%d, y=%d,z=%d, xdata=%f, ydata=%f, zdata=%f'%
    #              ('double' if event.dblclick else 'single', event.button,
    #                event.x, event.y, event.z, event.xdata, event.ydata, event.zdata))

    # cid = fig.canvas.mpl_connect('button_press_event', onclick)

def randrange(n, vmin, vmax):
    return (vmax - vmin)*np.random.rand(n) + vmin

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
n = 15

for m, zlow, zhigh in [('o', -50, -25), ('^', -30, -5)]:
    xs = randrange(n, 23, 32)
    ys = randrange(n, 0, 100)
    zs = randrange(n, zlow, zhigh)
    ax.scatter(xs, ys, zs, marker=m,picker=True)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

eventHandleSet()

plt.show()

Actual outcome

图片
As you can see from the diagram, the z coordinate of the point in the red circle is wrong.It should be between -40 and -50, not -12. ("pick_event")

图片
You can see from the graph that you can't get the z coordinates by clicking on the event, only the x and y coordinates. ("button_press_event")

Matplotlib version

  • Operating system: win7 64bit
  • Matplotlib version: 3.1.1
  • Matplotlib backend (print(matplotlib.get_backend())):TkAgg
  • Python version:3.7.3
  • Jupyter version (if applicable):
  • Other libraries: qt5.9.8
@Daemon1992 Daemon1992 changed the title How to handle 3d event_handling? How do I get the point coordinates (xyz) on a 3d graph? Jan 8, 2020
@timhoffm timhoffm added the Community support Users in need of help. label Jan 8, 2020
@jgwilliams17
Copy link

Hi @Daemon1992, I'm having the same issue you had last year (coordinates being returned are not the 3D coordinates displayed on the graph). Did you manage to resolve this?

@acloudinmybluesky
Copy link

Hi @Daemon1992
Hi @jgwilliams17
I also have the same problem (the coordinates returned are mostly wrong). Did you manage to find a solution?

@Rickfdalton
Copy link

I came across the exact same issue, any remedies??

@stefanie-theodora
Copy link

I'm having the same problem, were you able to find a fix?

@jklymak
Copy link
Member

jklymak commented Oct 14, 2024

It is not possible to uniquely get the coordinates in a 3d plot when they are projected onto a 2d screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community support Users in need of help.
Projects
None yet
Development

No branches or pull requests

7 participants