【发布时间】:2018-03-17 00:04:02
【问题描述】:
我正在 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 以使比例的下限和透明。看看这对你有用。我相信它也可以通过编程方式完成。
-
其实还不错,而且比我预期的要好看。但我仍然希望在图像上方看到一条(微弱的)网格线。