nochenon
nochenon

Reputation: 346

Use pyqtgraph to draw squares in xy coordinates

I am trying to use pyqtgraph to draw a semiconductor wafer map, which is consisted of thousands of squares in different colors and (x, y) coordinates, I'm also expecting to implement hover/mouse click event on the plot.

Here is what I did in PColorMeshItem, but it gives me IndexError.

"""
Demonstrates very basic use of PColorMeshItem
"""

import numpy as np
import pyqtgraph as pg

app = pg.mkQApp("PColorMesh Example")

## Create window with GraphicsView widget
win = pg.GraphicsLayoutWidget()
win.show()  ## show widget alone in its own window
win.setWindowTitle('pyqtgraph example: pColorMeshItem')
view = win.addViewBox()

## Create data
x_min = 0
x_max = 2
y_min = 0
y_max = 2
x = np.arange(x_min, x_max+2, 1, dtype=np.int16)
y = np.arange(y_min, y_max+2, 1, dtype=np.int16)
xmesh, ymesh = np.meshgrid(x, y, indexing='xy')
# init with all np.nan to hide all squares
z = np.full((y.size-1, x.size-1), np.nan)

# fill data in specific area
z[(1, 1, 1), (0, 1, 2)] = 1
z[(0, 1, 2), (1, 1, 1)] = 1

pcmi = pg.PColorMeshItem(xmesh, ymesh, z)
view.addItem(pcmi)

if __name__ == '__main__':
    pg.exec()

Error:

File "/usr/local/lib/python3.9/site-packages/pyqtgraph/graphicsItems/PColorMeshItem.py", line 139, in __init__
    self.setData(*args)
  File "/usr/local/lib/python3.9/site-packages/pyqtgraph/graphicsItems/PColorMeshItem.py", line 258, in setData
    brushes = [lut[z] for z in norm[i].tolist()]
  File "/usr/local/lib/python3.9/site-packages/pyqtgraph/graphicsItems/PColorMeshItem.py", line 258, in <listcomp>
    brushes = [lut[z] for z in norm[i].tolist()]
IndexError: list index out of range

and here is the content of norm

[[-9223372036854775808 -9223372036854775808 -9223372036854775808]
 [-9223372036854775808 -9223372036854775808 -9223372036854775808]
 [-9223372036854775808 -9223372036854775808 -9223372036854775808]]

I don't know what other options I can use to draw a wafer map?

Upvotes: 0

Views: 431

Answers (1)

diko
diko

Reputation: 11

Not sure if this is still relevant, but the problem comes from the initialization of the z:

z = np.full((y.size-1, x.size-1), np.nan)

where the empty values are np.nan The colorMap scaling of PColorMeshItem uses an internal function to normalize the data. This somehow misses the np.nan. Thus, you may consider adjusting that part of the code to avoid the index error.

Upvotes: 1

Related Questions