plot_surface : 获取写在右下角的 x,y,z 值
我是 matplotlib 的新用户。使用 matplotlib 和plot_surface 绘制曲面 (3D) 时,会出现一个带有图形的窗口。在该窗口中,右下角有鼠标实际位置的坐标。是否可以访问这些值?
我在互联网上搜索过,但提出的解决方案很少。对于 2D 绘图,可以使用 tkinter.canvas 访问这些值,但在 3D 中,当使用相同的技术时,event.xdata 和 event.ydata 不会返回鼠标的正确位置。
I am a quite new user of matplotlib. When plotting a surface (3D) with matplotlib and plot_surface, a window appears with the graph. In that windows, on the bottom right corner there is the coordinates of the actual position of the mouse. Is is possible to gain access to these values?
I have search on internet but very few solutions are proposed. For a 2D plot, these values are accessible using a tkinter.canvas but in 3D, when using the same technique the event.xdata and event.ydata did not return the good position for the mouse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用ax.format_coord(mouseevent.xdata,mouseevent.ydata),您可以获取字符串中的x、y、z值
('x=0.222, y=0.452, z=0.826')
您可以从中提取值。例如对于 y 坐标:
With
ax.format_coord(mouseevent.xdata,mouseevent.ydata)
you get the x, y, z values in a string('x=0.222, y=0.452, z=0.826')
from which you can extract the values.For example for y-coordinate:
我尝试了@Thilo 的答案,但只收到了一个浮点数。使用 Python 3.8 和 Matplotlib 版本 3.2.1。
把他的函数修改为这个
非常感谢,因为如果没有这个答案,我永远不会知道像
format_coord
这样的东西存在。I tried @Thilo's answer and received only a single float. Using Python 3.8 and Matplotlib version 3.2.1.
Modified his function to this
Many thanks, because without that answer I would never knew something like
format_coord
exist.