【问题标题】:problems with displaying the coordinates of a point in matplotlib python在matplotlib python中显示点坐标的问题
【发布时间】:2018-12-22 09:22:38
【问题描述】:

当我使用 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()

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

【问题讨论】:

  • 你说的是什么意思?我想如果你在问题和期望的结果上多说一句的话会有所帮助。
  • 我认为该模块会在图表中获取鼠标的坐标,但是当我旋转图表时,鼠标的坐标会发生变化,因此每次图表旋转时我都会得到不同的坐标。

标签: python-3.x matplotlib mplcursors


【解决方案1】:

我已经解决了:

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)

如果添加这段代码,您将获得显示在点旁边的坐标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 2018-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多