【问题标题】:Use pyqtgraph to draw squares in xy coordinates使用pyqtgraph在xy坐标中绘制正方形
【发布时间】:2022-12-28 19:19:35
【问题描述】:

我正在尝试使用 pyqtgraph 绘制半导体晶圆图,它由数千个不同颜色和 (x, y) 坐标的正方形组成,我还希望在图上实现悬停/鼠标单击事件。

这是我在PColorMeshItem 中所做的,但它给了我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()

错误:

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

这是norm的内容

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

我不知道还有什么其他选项可以用来绘制晶圆图?

【问题讨论】:

    标签: python pyqtgraph


    【解决方案1】:

    不确定这是否仍然相关,但问题来自 z 的初始化:

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

    空值是 np.nan PColorMeshItem 的 colorMap 缩放使用内部函数来规范化数据。这不知何故错过了 np.nan。因此,您可以考虑调整该部分代码以避免索引错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 2014-11-24
      • 1970-01-01
      • 2020-05-17
      • 2018-06-24
      相关资源
      最近更新 更多