簡體   English   中英

在pyqtgraph中的圖像上顯示網格線

[英]Show grid lines over image in 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))

這是我看到的內容(縮小一點后)。 您會看到圖像的黑色區域遮蓋了網格線。

pyqtgraph圖像截圖

編輯 :可以在GUI中將黑色更改為透明(這不是我的首選,但暫時可以解決),因此您可以看到圖像下方的網格。 可以,但是我不知道如何在代碼中做到這一點。 如何從ImageView獲取查找表進行修改?

這是我所做的。

glw = pyqtgraph.GraphicsLayoutWidget()
pw = glw.addPlot(0, 0)

# Fix Axes ticks and grid
for key in pw.axes:
    ax = pw.getAxis(key)

    # Set the grid opacity
    if grid_is_visible:
        ax.setGrid(grid_opacity * 255)
    else:
        ax.setGrid(False)

    # Fix Z value making the grid on top of the image
    ax.setZValue(1)

我認為這確實引起了其他問題。 由於Qt表示事件的方式,它可能是上下文菜單,或者與平移和縮放有關。 一個軸具有事件優先級,並阻止事件傳播以使其他軸平移和縮放。 我向pyqtgraph提交了拉取請求,因此可能不再是問題。 我不記得是什么引起了問題。 它可能對您來說很好。 我做了很多其他事情,例如更改背景色和更改視圖框背景色,這導致了一些小問題。

注意,我還更改了圖像z值。 您不必如此。

imv.setZValue(1)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM