Closed
Description
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