我在pyqtgraph中绘制图像,我希望能够看到网格线。但网格线总是绘制在图像下方,因此图像的任何黑色区域都会遮挡网格。这是一个相当简单的例子:在pyqtgraph中显示网格线图像
import matplotlib # necessary for interactive plots in pyqtgraph
import pyqtgraph as pg
import numpy as np
n = 100000
sigma_y = 1e-3
sigma_x = 1e-3
x0 = np.matrix([np.random.normal(0, sigma_x, n), np.random.normal(0, sigma_y, n)])
bins = 30
histogram, x_edges, y_edges = np.histogram2d(np.asarray(x0)[0], np.asarray(x0)[1], bins)
x_range = x_edges[-1] - x_edges[0]
y_range = y_edges[-1] - y_edges[0]
imv = pg.ImageView(view=pg.PlotItem())
imv.show()
imv.setPredefinedGradient('thermal')
imv.getView().showGrid(True, True)
imv.setImage(histogram, pos=(x_edges[0], y_edges[0]), scale=(x_range/bins, y_range/bins))
这是我看到的(缩小一点后)。您可以看到图像的黑色区域遮挡网格线。
编辑:有可能在GUI中的黑色改变为透明(不是我的第一选择,但现在一个确定的解决方法),所以你可以看到下面的图像的网格。这工作正常,但我不知道如何在代码中做到这一点。我如何从ImageView
中获取查找表来修改它?
色阶由几种颜色之间的渐变组成。这些由颜色条右侧的三角形表示。如果您单击底部的黑色三角形,将会弹出一个对话框,您可以从该对话框中更改该设置点的颜色。将alpha分量设置为0以使下面的和比例透明。看到它适合你。我相信它也可以通过编程来完成。 – titusjan
这实际上并不坏,并且比我预期的更好看。但我仍然希望在图像上方看到一条(微弱的)网格线。 – benshepherd