Python pyqtgraph.GraphItem() Examples

The following are 12 code examples of pyqtgraph.GraphItem(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyqtgraph , or try the search function .
Example #1
Source File: chain.py    From tf-pose with Apache License 2.0 5 votes vote down vote up
def makeGraph(self):
        #g1 = pg.GraphItem(pos=self.pos, adj=self.links[self.rope], pen=0.2, symbol=None)
        brushes = np.where(self.fixed, pg.mkBrush(0,0,0,255), pg.mkBrush(50,50,200,255))
        g2 = pg.GraphItem(pos=self.pos, adj=self.links[self.push & self.pull], pen=0.5, brush=brushes, symbol='o', size=(self.mass**0.33), pxMode=False)
        p = pg.ItemGroup()
        #p.addItem(g1)
        p.addItem(g2)
        return p 
Example #2
Source File: CustomGraphItem.py    From tf-pose with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        self.dragPoint = None
        self.dragOffset = None
        self.textItems = []
        pg.GraphItem.__init__(self)
        self.scatter.sigClicked.connect(self.clicked) 
Example #3
Source File: CustomGraphItem.py    From tf-pose with Apache License 2.0 5 votes vote down vote up
def updateGraph(self):
        pg.GraphItem.setData(self, **self.data)
        for i,item in enumerate(self.textItems):
            item.setPos(*self.data['pos'][i]) 
Example #4
Source File: uiKLine.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def add_trans(self, tns_dict):
        """
        添加事务画线
        {'start_time','end_time','tns_type','start_price','end_price','start_x','end_x','completed'}
        :return:
        """
        if len(self.datas)==0:
            print(u'No datas exist',file=sys.stderr)
            return
        tns = copy.copy(tns_dict)

        completed = tns.get('completed', False)
        end_price = tns.get('end_price',0)
        if not completed:
            end_x = len(self.datas) -1
            end_price = self.datas[end_x]['close']
            tns['end_x'] = end_x
            tns['end_price'] = end_price
            tns['completed'] = False
        else:
            tns['end_x'] = self.axisTime.get_x_by_time(tns['end_time'])

        tns['start_x'] = self.axisTime.get_x_by_time(tns['start_time'])
        # 将上一个线段设置为True
        if len(self.list_trans) > 0:
            self.list_trans[-1]['completed'] = True
        pos = np.array([[tns['start_x'],tns['start_price']],[tns['end_x'],tns['end_price']]])

        tns_line = pg.GraphItem(pos=pos, adj=np.array([[0,1]]))
        self.pi_main.addItem(tns_line)
        self.list_trans.append(tns) 
Example #5
Source File: play.py    From simulator with GNU General Public License v3.0 5 votes vote down vote up
def draw_net(self):
        pg.setConfigOptions(antialias=True)
        self.w = pg.GraphicsWindow()    # Create new window like matplotlib pyplot
        self.w.resize(800, 600)
        self.w.setWindowTitle('Overlay Network of the Team')
        self.v = self.w.addViewBox()  # Add ViewBox that would contain all the graphics i.e graph structure
        self.v.setAspectLocked()
        self.G = Graph()  # Child class of pg.GraphItem that would contain all the nodes and edges
        self.v.addItem(self.G)
        self.color_map = {'peer': (169, 188, 245, 255), 'monitor': (
            169, 245, 208, 255), 'malicious': (247, 129, 129, 255)} 
Example #6
Source File: qtGraph.py    From simulator with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        self.textItems = []
        pg.GraphItem.__init__(self)
        self.pos = []
        self.edges = [[0, 0]]    # edges should have atleast one edge else it will throw error
        self.texts = []
        self.V = 0
        self.lineColor = []
        self.nodeColors = []

    # Clear previous data and set new data, it is overrided to update nodes labels 
Example #7
Source File: qtGraph.py    From simulator with GNU General Public License v3.0 5 votes vote down vote up
def updateGraph(self):
        pg.GraphItem.setData(self, **self.data)
        for i, item in enumerate(self.textItems):
            item.setPos(*self.data['pos'][i]) 
Example #8
Source File: chain.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def makeGraph(self):
        #g1 = pg.GraphItem(pos=self.pos, adj=self.links[self.rope], pen=0.2, symbol=None)
        brushes = np.where(self.fixed, pg.mkBrush(0,0,0,255), pg.mkBrush(50,50,200,255))
        g2 = pg.GraphItem(pos=self.pos, adj=self.links[self.push & self.pull], pen=0.5, brush=brushes, symbol='o', size=(self.mass**0.33), pxMode=False)
        p = pg.ItemGroup()
        #p.addItem(g1)
        p.addItem(g2)
        return p 
Example #9
Source File: CustomGraphItem.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        self.dragPoint = None
        self.dragOffset = None
        self.textItems = []
        pg.GraphItem.__init__(self)
        self.scatter.sigClicked.connect(self.clicked) 
Example #10
Source File: CustomGraphItem.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def updateGraph(self):
        pg.GraphItem.setData(self, **self.data)
        for i,item in enumerate(self.textItems):
            item.setPos(*self.data['pos'][i]) 
Example #11
Source File: plotting.py    From pygsp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _qtg_plot_graph(G, edges, vertex_size, title):

    qtg, gl, QtGui = _import_qtg()

    if G.coords.shape[1] == 2:

        window = qtg.GraphicsWindow()
        window.setWindowTitle(title)
        view = window.addViewBox()
        view.setAspectLocked()

        if edges:
            pen = tuple(np.array(G.plotting['edge_color']) * 255)
        else:
            pen = None

        adj = _get_coords(G, edge_list=True)

        g = qtg.GraphItem(pos=G.coords, adj=adj, pen=pen,
                          size=vertex_size/10)
        view.addItem(g)

        global _qtg_windows
        _qtg_windows.append(window)

    elif G.coords.shape[1] == 3:
        if not QtGui.QApplication.instance():
            QtGui.QApplication([])  # We want only one application.
        widget = gl.GLViewWidget()
        widget.opts['distance'] = 10
        widget.show()
        widget.setWindowTitle(title)

        if edges:
            x, y, z = _get_coords(G)
            pos = np.stack((x, y, z), axis=1)
            g = gl.GLLinePlotItem(pos=pos, mode='lines',
                                  color=G.plotting['edge_color'])
            widget.addItem(g)

        gp = gl.GLScatterPlotItem(pos=G.coords, size=vertex_size/3,
                                  color=G.plotting['vertex_color'])
        widget.addItem(gp)

        global _qtg_widgets
        _qtg_widgets.append(widget) 
Example #12
Source File: plotting.py    From pygsp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _qtg_plot_signal(G, signal, edges, vertex_size, limits, title):

    qtg, gl, QtGui = _import_qtg()

    if G.coords.shape[1] == 2:
        window = qtg.GraphicsWindow(title)
        view = window.addViewBox()

    elif G.coords.shape[1] == 3:
        if not QtGui.QApplication.instance():
            QtGui.QApplication([])  # We want only one application.
        widget = gl.GLViewWidget()
        widget.opts['distance'] = 10
        widget.show()
        widget.setWindowTitle(title)

    if edges:

        if G.coords.shape[1] == 2:
            adj = _get_coords(G, edge_list=True)
            pen = tuple(np.array(G.plotting['edge_color']) * 255)
            g = qtg.GraphItem(pos=G.coords, adj=adj, symbolBrush=None,
                              symbolPen=None, pen=pen)
            view.addItem(g)

        elif G.coords.shape[1] == 3:
            x, y, z = _get_coords(G)
            pos = np.stack((x, y, z), axis=1)
            g = gl.GLLinePlotItem(pos=pos, mode='lines',
                                  color=G.plotting['edge_color'])
            widget.addItem(g)

    pos = [1, 8, 24, 40, 56, 64]
    color = np.array([[0, 0, 143, 255], [0, 0, 255, 255], [0, 255, 255, 255],
                      [255, 255, 0, 255], [255, 0, 0, 255], [128, 0, 0, 255]])
    cmap = qtg.ColorMap(pos, color)

    signal = 1 + 63 * (signal - limits[0]) / limits[1] - limits[0]

    if G.coords.shape[1] == 2:
        gp = qtg.ScatterPlotItem(G.coords[:, 0],
                                 G.coords[:, 1],
                                 size=vertex_size/10,
                                 brush=cmap.map(signal, 'qcolor'))
        view.addItem(gp)

    if G.coords.shape[1] == 3:
        gp = gl.GLScatterPlotItem(pos=G.coords,
                                  size=vertex_size/3,
                                  color=cmap.map(signal, 'float'))
        widget.addItem(gp)

    if G.coords.shape[1] == 2:
        global _qtg_windows
        _qtg_windows.append(window)
    elif G.coords.shape[1] == 3:
        global _qtg_widgets
        _qtg_widgets.append(widget)