Skip to content Skip to sidebar Skip to footer

Pyqtgraph Change Color Of Node And Its Edges On Click

I'm working with pyqtgraph to create an interactive network of nodes and edges (initially from this question, all code needed comes from here). I'm trying to change the color of a

Solution 1:

I don't know why scatter.setPen(pens) or scatter.setBrush(brushes) is not working. As an alternative, you can use g.setData like this:

def clicked(self, scatter, pts):
    data_list = scatter.data.tolist()
    mypoint = [tup for tup in data_list if pts[0] in tup][0]
    mypoint_index = data_list.index(mypoint)
    mypoint_edges = [tup for tup in self.data['adj'] if mypoint_index in tup]

    data = scatter.getData()
    newPos = np.vstack([data[0],data[1]]).transpose()
    newLines = lines.copy()
    symbolBrushs = [None] * len(data[0])
    symbolBrushs[mypoint_index] = pg.mkBrush(color=(255, 0, 0))
    for i in range(len(mypoint_edges)):
        for j in range(len(adj)):
            if np.array_equal(adj[j], mypoint_edges[i]):
                break
        index = j
        newLines.itemset(index, (255,0,0,255,1))
    g.setData(pos=newPos, adj=adj, pen=newLines, size=1, symbol=symbols, pxMode=False, text=texts, symbolBrush=symbolBrushs)

    self.updateGraph()

And this is the result:

enter image description here

Post a Comment for "Pyqtgraph Change Color Of Node And Its Edges On Click"