在 matplotlib 中显示点坐标的问题 python

problems with displaying the coordinates of a point in matplotlib python

我在使用 2D 绘图时找到了解决此问题的方法,但我正在使用 3D 绘图。当前的代码是:

from mpl_toolkits import mplot3d
import matplotlib.pyplot as plt
import mplcursors
import numpy as np

x = np.array([0,1,2,3,4,5,6,7,8,9])
y = np.array([9,8,7,6,5,4,3,2,1,0])
z = np.array([0,9,1,8,2,7,3,6,4,5])

fig=plt.figure()

ax=fig.gca(projection='3d')

ax.scatter(x,y,z,zdir='z',s=20,c=None, depthshade=True)

mplcursors.cursor(hover=True)

plt.show()

我通过这个程序获得了坐标,但是如果我旋转我的图表,它们就会改变。我怎样才能解决这个问题?我认为最简单的方法是以某种方式回忆起我悬停的点的坐标。但是我该怎么做呢?

我已经修复了:

zdirs = (None, 'x', 'y', 'z', (1, 1, 0), (1, 1, 1))

for xc, yc, zc in zip(x, y, z):
    label = '(%d, %d, %d)' % (xc, yc, zc)
    ax.text(xc, yc, zc, label)

如果添加了这段代码,您会在点旁边显示坐标。