Matplotlib - plot_surface : get the x,y,z values written in the bottom right corner

百般思念 提交于 2019-11-30 18:50:00

问题


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.

Thank you in advance for your precious help,

Antoine


回答1:


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:

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)


来源:https://stackoverflow.com/questions/6748184/matplotlib-plot-surface-get-the-x-y-z-values-written-in-the-bottom-right-cor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!