本文介绍了Matplotlib - plot_surface:获取写在右下角的x,y,z值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 ?

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

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.

感谢您提供宝贵的帮助,

Thank you in advance for your precious help,

Antoine

推荐答案

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

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.

协调:

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)

这篇关于Matplotlib - plot_surface:获取写在右下角的x,y,z值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 17:21