gpt4 book ai didi

python - plot_surface : get the x, y,z值写在右下角

转载 作者:太空宇宙 更新时间:2023-11-03 13:51:50 30 4
gpt4 key购买 nike

我是 matplotlib 的新用户。使用 matplotlib 和 plot_surface 绘制曲面 (3D) 时,会出现一个带有图形的窗口。在该窗口中,右下角有鼠标实际位置的坐标。是否有可能访问这些值?

我在互联网上搜索过,但提出的解决方案很少。对于 2D 绘图,可以使用 tkinter.canvas 访问这些值,但在 3D 中,当使用相同的技术时,event.xdata 和 event.ydata 不会返回鼠标的正确位置。

最佳答案

使用 ax.format_coord(mouseevent.xdata,mouseevent.ydata) 可以在字符串中得到 x、y、z 值 ('x=0.222, y=0.452, z= 0.826') 您可以从中提取值。

例如 y 坐标:

def gety(x,y):
s = ax.format_coord(x,y)
out = ""
for i in range(s.find('y')+2,s.find('z')-2):
out = out+s[i]
return float(out)

关于python - plot_surface : get the x, y,z值写在右下角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6748184/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com