我如何从图形画布类获取坐标?

时间:2019-09-12 15:10:51

标签: python pyqt5

我想创建一个函数,当您在地图上单击鼠标点时,返回x,y值

lonGrid, latGrid = np.meshgrid(self.lonBathymetry[lon_inds[0 [0:-1:stepLon]], self.latBathymetry[lat_inds[0][0:-1:stepLat]])
    bathymetry = self.gb.variables['elevation'][ lat_inds[0][0:-1:stepLat] , lon_inds[0][0:-1:stepLon]] 

    self.m  = Basemap(ax=self.axes, projection='cyl',llcrnrlat=lat_min,urcrnrlat=lat_max,\
        llcrnrlon=lon_min,urcrnrlon=lon_max,resolution=res)

    xi, yi =self.m(lonGrid, latGrid)

def mousePressEvent(self, event):

    lonGrid= self.canvas.lonGrid
    latGrid= self.canvas.latGrid

    x = event.latGrid()
    y = event.lonGrid()

1 个答案:

答案 0 :(得分:0)

如果这是matplotlib画布,则坐标应在event.xevent.y中可用。

来源:https://matplotlib.org/3.1.1/users/event_handling.html