从 pyqtgraph.image 图中获取相应的 x、y、z 值
Obtaining the corresponding x,y,z values from pyqtgraph.image plot
我有一系列使用以下 Python (2.7) 代码生成的图像:
import numpy as np
import pyqtgraph as pg
data = np.ones((230,10,10)) #for example; not quite the data that resulted in this image, but the numbers themselves are not the focus
img = pg.image(data)
pg.QtGui.QApplication.exec_()
如何从底部绘图中获取相应的 'x' 值?另外,如何从上图中的每个正方形中获取相应的 (x,y) 坐标?
Whosebug 上的各种答案都集中在 "ImageView" 上,但如果可以的话,我会尽量避免它 - 由于某些原因,我无法使用 ImageView 生成类似的图 - 没有任何结果, Python 只是冻结。我也是 PyQtGraph 的新手。
pg.ImageView is actually the same as pg.image 它在图像中创建一个图像视图 window
所以请尝试以下操作来获取您的代码 运行 ImageView
import numpy as np
import pyqtgraph as pg
data = np.ones((230,10,10))
imv = pg.ImageView()
imv.setImage(data)
imv.show()
pg.QtGui.QApplication.exec_()
关于坐标,底部的图是从 Region of Interest (ROI) 生成的,以获得 x 和 y 坐标,您需要向图像添加 ROI。
roi = pg.ROI([0,0],[1,1],pen=pg.mkPen('r',width=2))
imv.addItem(roi)
def getcoordinates(roi):
data2,xdata = roi.getArrayRegion(data,imv.imageItem,returnMappedCoords=True)
print(xdata)
roi.sigRegionChanged.connect(getcoordinates)
这将打印出 ROI 悬停的坐标
注意:上面的代码是 python 3.7,因为这是我正在使用的。所以你必须调整一些东西以适应 python 2.7
我有一系列使用以下 Python (2.7) 代码生成的图像:
import numpy as np
import pyqtgraph as pg
data = np.ones((230,10,10)) #for example; not quite the data that resulted in this image, but the numbers themselves are not the focus
img = pg.image(data)
pg.QtGui.QApplication.exec_()
如何从底部绘图中获取相应的 'x' 值?另外,如何从上图中的每个正方形中获取相应的 (x,y) 坐标?
Whosebug 上的各种答案都集中在 "ImageView" 上,但如果可以的话,我会尽量避免它 - 由于某些原因,我无法使用 ImageView 生成类似的图 - 没有任何结果, Python 只是冻结。我也是 PyQtGraph 的新手。
pg.ImageView is actually the same as pg.image 它在图像中创建一个图像视图 window
所以请尝试以下操作来获取您的代码 运行 ImageView
import numpy as np
import pyqtgraph as pg
data = np.ones((230,10,10))
imv = pg.ImageView()
imv.setImage(data)
imv.show()
pg.QtGui.QApplication.exec_()
关于坐标,底部的图是从 Region of Interest (ROI) 生成的,以获得 x 和 y 坐标,您需要向图像添加 ROI。
roi = pg.ROI([0,0],[1,1],pen=pg.mkPen('r',width=2))
imv.addItem(roi)
def getcoordinates(roi):
data2,xdata = roi.getArrayRegion(data,imv.imageItem,returnMappedCoords=True)
print(xdata)
roi.sigRegionChanged.connect(getcoordinates)
这将打印出 ROI 悬停的坐标
注意:上面的代码是 python 3.7,因为这是我正在使用的。所以你必须调整一些东西以适应 python 2.7