Python pyqtgraph.GraphicsWindow() Examples
The following are 21
code examples of pyqtgraph.GraphicsWindow().
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: test_svg.py From tf-pose with Apache License 2.0 | 6 votes |
def test_plotscene(): tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name print("using %s as a temporary file" % tempfilename) pg.setConfigOption('foreground', (0,0,0)) w = pg.GraphicsWindow() w.show() p1 = w.addPlot() p2 = w.addPlot() p1.plot([1,3,2,3,1,6,9,8,4,2,3,5,3], pen={'color':'k'}) p1.setXRange(0,5) p2.plot([1,5,2,3,4,6,1,2,4,2,3,5,3], pen={'color':'k', 'cosmetic':False, 'width': 0.3}) app.processEvents() app.processEvents() ex = pg.exporters.SVGExporter(w.scene()) ex.export(fileName=tempfilename) # clean up after the test is done os.unlink(tempfilename)
Example #2
Source File: test_ViewBox.py From tf-pose with Apache License 2.0 | 6 votes |
def init_viewbox(): """Helper function to init the ViewBox """ global win, vb win = pg.GraphicsWindow() win.ci.layout.setContentsMargins(0,0,0,0) win.resize(200, 200) win.show() vb = win.addViewBox() # set range before viewbox is shown vb.setRange(xRange=[0, 10], yRange=[0, 10], padding=0) # required to make mapFromView work properly. qtest.qWaitForWindowShown(win) g = pg.GridItem() vb.addItem(g) app.processEvents()
Example #3
Source File: test_PlotCurveItem.py From tf-pose with Apache License 2.0 | 6 votes |
def test_PlotCurveItem(): p = pg.GraphicsWindow() p.ci.layout.setContentsMargins(4, 4, 4, 4) # default margins vary by platform v = p.addViewBox() p.resize(200, 150) data = np.array([1,4,2,3,np.inf,5,7,6,-np.inf,8,10,9,np.nan,-1,-2,0]) c = pg.PlotCurveItem(data) v.addItem(c) v.autoRange() # Check auto-range works. Some platform differences may be expected.. checkRange = np.array([[-1.1457564053237301, 16.145756405323731], [-3.076811473165955, 11.076811473165955]]) assert np.allclose(v.viewRange(), checkRange) assertImageApproved(p, 'plotcurveitem/connectall', "Plot curve with all points connected.") c.setData(data, connect='pairs') assertImageApproved(p, 'plotcurveitem/connectpairs', "Plot curve with pairs connected.") c.setData(data, connect='finite') assertImageApproved(p, 'plotcurveitem/connectfinite', "Plot curve with finite points connected.") c.setData(data, connect=np.array([1,1,1,0,1,1,0,0,1,0,0,0,1,1,0,0])) assertImageApproved(p, 'plotcurveitem/connectarray', "Plot curve with connection array.")
Example #4
Source File: test_svg.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 6 votes |
def test_plotscene(): tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name print("using %s as a temporary file" % tempfilename) pg.setConfigOption('foreground', (0,0,0)) w = pg.GraphicsWindow() w.show() p1 = w.addPlot() p2 = w.addPlot() p1.plot([1,3,2,3,1,6,9,8,4,2,3,5,3], pen={'color':'k'}) p1.setXRange(0,5) p2.plot([1,5,2,3,4,6,1,2,4,2,3,5,3], pen={'color':'k', 'cosmetic':False, 'width': 0.3}) app.processEvents() app.processEvents() ex = pg.exporters.SVGExporter(w.scene()) ex.export(fileName=tempfilename) # clean up after the test is done os.unlink(tempfilename)
Example #5
Source File: test_svg.py From soapy with GNU General Public License v3.0 | 6 votes |
def test_plotscene(): tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name print("using %s as a temporary file" % tempfilename) pg.setConfigOption('foreground', (0,0,0)) w = pg.GraphicsWindow() w.show() p1 = w.addPlot() p2 = w.addPlot() p1.plot([1,3,2,3,1,6,9,8,4,2,3,5,3], pen={'color':'k'}) p1.setXRange(0,5) p2.plot([1,5,2,3,4,6,1,2,4,2,3,5,3], pen={'color':'k', 'cosmetic':False, 'width': 0.3}) app.processEvents() app.processEvents() ex = pg.exporters.SVGExporter(w.scene()) ex.export(fileName=tempfilename) # clean up after the test is done os.unlink(tempfilename)
Example #6
Source File: test_ViewBox.py From soapy with GNU General Public License v3.0 | 6 votes |
def init_viewbox(): """Helper function to init the ViewBox """ global win, vb win = pg.GraphicsWindow() win.ci.layout.setContentsMargins(0,0,0,0) win.resize(200, 200) win.show() vb = win.addViewBox() # set range before viewbox is shown vb.setRange(xRange=[0, 10], yRange=[0, 10], padding=0) # required to make mapFromView work properly. qtest.qWaitForWindowShown(win) g = pg.GridItem() vb.addItem(g) app.processEvents()
Example #7
Source File: test_PlotCurveItem.py From soapy with GNU General Public License v3.0 | 6 votes |
def test_PlotCurveItem(): p = pg.GraphicsWindow() p.ci.layout.setContentsMargins(4, 4, 4, 4) # default margins vary by platform v = p.addViewBox() p.resize(200, 150) data = np.array([1,4,2,3,np.inf,5,7,6,-np.inf,8,10,9,np.nan,-1,-2,0]) c = pg.PlotCurveItem(data) v.addItem(c) v.autoRange() # Check auto-range works. Some platform differences may be expected.. checkRange = np.array([[-1.1457564053237301, 16.145756405323731], [-3.076811473165955, 11.076811473165955]]) assert np.allclose(v.viewRange(), checkRange) assertImageApproved(p, 'plotcurveitem/connectall', "Plot curve with all points connected.") c.setData(data, connect='pairs') assertImageApproved(p, 'plotcurveitem/connectpairs', "Plot curve with pairs connected.") c.setData(data, connect='finite') assertImageApproved(p, 'plotcurveitem/connectfinite', "Plot curve with finite points connected.") c.setData(data, connect=np.array([1,1,1,0,1,1,0,0,1,0,0,0,1,1,0,0])) assertImageApproved(p, 'plotcurveitem/connectarray', "Plot curve with connection array.")
Example #8
Source File: lockbox_widget.py From pyrpl with GNU General Public License v3.0 | 6 votes |
def init_gui(self): #self.main_layout = QtWidgets.QVBoxLayout(self) self.init_main_layout(orientation="vertical") self.init_attribute_layout() self.win = pg.GraphicsWindow(title="Expected signal") self.plot_item = self.win.addPlot(title='Expected ' + self.module.name) self.plot_item.showGrid(y=True, x=True, alpha=1.) self.curve = self.plot_item.plot(pen='y') self.curve_slope = self.plot_item.plot(pen=pg.mkPen('b', width=5)) self.symbol = self.plot_item.plot(pen='b', symbol='o') self.main_layout.addWidget(self.win) self.button_calibrate = QtWidgets.QPushButton('Calibrate') self.main_layout.addWidget(self.button_calibrate) self.button_calibrate.clicked.connect(lambda: self.module.calibrate()) self.input_calibrated()
Example #9
Source File: attribute_widgets.py From pyrpl with GNU General Public License v3.0 | 5 votes |
def _make_widget(self): """ Sets the widget (here a QCheckbox) :return: """ self.widget = pg.GraphicsWindow(title="Plot") legend = getattr(self.module.__class__, self.attribute_name).legend self.pw = self.widget.addPlot(title="%s vs. time (s)"%legend) self.plot_start_time = self.time() self.curves = {} setattr(self.module.__class__, '_' + self.attribute_name + '_pw', self.pw)
Example #10
Source File: test_ref_cycles.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def test_GraphicsWindow(): def mkobjs(): w = pg.GraphicsWindow() p1 = w.addPlot() v1 = w.addViewBox() return mkrefs(w, p1, v1) for i in range(5): assert_alldead(mkobjs())
Example #11
Source File: gui.py From audio-reactive-led-strip with MIT License | 5 votes |
def __init__(self, width=800, height=450, title=''): # Create GUI window self.app = QtGui.QApplication([]) self.win = pg.GraphicsWindow(title) self.win.resize(width, height) self.win.setWindowTitle(title) # Create GUI layout self.layout = QtGui.QVBoxLayout() self.win.setLayout(self.layout)
Example #12
Source File: loop.py From pyrpl with GNU General Public License v3.0 | 5 votes |
def __init__(self, title="plotwindow"): self.win = pg.GraphicsWindow(title=title) self.pw = self.win.addPlot() self.curves = {} self.win.show() self.plot_start_time = time()
Example #13
Source File: test_ref_cycles.py From tf-pose with Apache License 2.0 | 5 votes |
def test_GraphicsWindow(): def mkobjs(): w = pg.GraphicsWindow() p1 = w.addPlot() v1 = w.addViewBox() return mkrefs(w, p1, v1) for i in range(5): assert_alldead(mkobjs())
Example #14
Source File: test_ref_cycles.py From soapy with GNU General Public License v3.0 | 5 votes |
def test_GraphicsWindow(): def mkobjs(): w = pg.GraphicsWindow() p1 = w.addPlot() v1 = w.addViewBox() return mkrefs(w, p1, v1) for i in range(5): assert_alldead(mkobjs())
Example #15
Source File: plotter.py From digikala_history with MIT License | 5 votes |
def __init__(self, parent=None, **kargs): pg.GraphicsWindow.__init__(self, **kargs) self.setParent(parent) self.setWindowTitle('') # Enable antialiasing for prettier plots pg.setConfigOptions(antialias=True) self.p6 = self.addPlot(title="") self.curve = self.p6.plot(pen='r')
Example #16
Source File: play.py From simulator with GNU General Public License v3.0 | 5 votes |
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 #17
Source File: attribute_widgets.py From pyrpl with GNU General Public License v3.0 | 4 votes |
def _make_widget(self): self.widget = pg.GraphicsWindow(title="Curve") self.plot_item = self.widget.addPlot(title="Curve") self.plot_item_phase = self.widget.addPlot(row=1, col=0, title="Phase (deg)") self.plot_item_phase.setXLink(self.plot_item) self.plot_item.showGrid(y=True, alpha=1.) self.plot_item_phase.showGrid(y=True, alpha=1.) self.curve = self.plot_item.plot(pen='g') self.curve_phase = self.plot_item_phase.plot(pen='g') self._is_real = True self._set_real(True) #def _set_widget_value(self, new_value): # data = new_value # if data is None: # return # shape = np.shape(new_value) # if len(shape)>2: # raise ValueError("Shape of data should be (1) or (2, 1)") # if len(shape)==1: # x = np.linspace(0, len(data), len(data)) # y = [data] # if len(shape)==2: # if shape[0] == 1: # x = np.linspace(0, len(data), len(data[0])) # y = [data[0]] # if shape[0] >= 2: # x = data[0] # y = data[1:] # self._set_real(np.isreal(y).all()) # for i, values in enumerate(y): # self._display_curve_index(x, values, i) # while (i + 1 < len(self.curves)): # delete remaining curves # i += 1 # self.curves[i].hide() #def _display_curve_index(self, x, values, i): # y_mag = values if self._is_real else self._magnitude(values) # y_phase = np.zeros(len(values)) if self._is_real else \ # self._phase(values) # if len(self.curves)<=i: # color = self._defaultcolors[i%len(self._defaultcolors)] # self.curves.append(self.plot_item.plot(pen=color)) # self.curves_phase.append(self.plot_item_phase.plot(pen=color)) # self.curves[i].setData(x, y_mag) # self.curves_phase[i].setData(x, y_phase)
Example #18
Source File: spec_an_widget.py From pyrpl with GNU General Public License v3.0 | 4 votes |
def init_gui(self): """ Sets up the gui. """ self.ch_col = ('magenta', 'blue', 'green') self.last_data = None self.init_main_layout(orientation="vertical") #self.main_layout = QtWidgets.QVBoxLayout() self.module.__dict__['curve_name'] = 'pyrpl spectrum' self.init_attribute_layout() self.other_widget = OtherAttributesWidget(self) self.attribute_layout.addWidget(self.other_widget) self.iqmode_widget = IqModeAttributesWidget(self) self.attribute_layout.addWidget(self.iqmode_widget) self.baseband_widget = BasebandAttributesWidget(self) self.attribute_layout.addWidget(self.baseband_widget) self.button_layout = QtWidgets.QHBoxLayout() self.setLayout(self.main_layout) # self.setWindowTitle("Spec. An.") #self.win = pg.GraphicsWindow(title="PSD") #self.main_layout.addWidget(self.win) self.win2 = DataWidget(title='Spectrum') self.main_layout.addWidget(self.win2) #self.plot_item = self.win.addPlot(title="PSD") #self.curve = self.plot_item.plot(pen=self.ch_col[0][0]) #self.curve2 = self.plot_item.plot(pen=self.ch_col[1][0]) # input2 # spectrum in # baseband #self.curve_cross = self.plot_item.plot(pen=self.ch_col[2][0]) # # curve for super(SpecAnWidget, self).init_gui() aws = self.attribute_widgets aws['display_input1_baseband'].setStyleSheet("color: %s" % self.ch_col[0]) aws['display_input2_baseband'].setStyleSheet("color: %s" % self.ch_col[1]) aws['display_cross_amplitude'].setStyleSheet("color: %s" % self.ch_col[2]) # Not sure why the stretch factors in button_layout are not good by # default... self.attribute_layout.addStretch(1) self.update_baseband_visibility()
Example #19
Source File: plotting.py From pygsp with BSD 3-Clause "New" or "Revised" License | 4 votes |
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 #20
Source File: plotting.py From pygsp with BSD 3-Clause "New" or "Revised" License | 4 votes |
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)
Example #21
Source File: plotting.py From pygsp with BSD 3-Clause "New" or "Revised" License | 4 votes |
def _plot_spectrogram(G, node_idx): r"""Plot the graph's spectrogram. Parameters ---------- node_idx : ndarray Order to sort the nodes in the spectrogram. By default, does not reorder the nodes. Notes ----- This function is only implemented for the pyqtgraph backend at the moment. Examples -------- >>> G = graphs.Ring(15) >>> G.plot_spectrogram() """ from pygsp import features qtg, _, _ = _import_qtg() if not hasattr(G, 'spectr'): features.compute_spectrogram(G) M = G.spectr.shape[1] spectr = G.spectr[node_idx, :] if node_idx is not None else G.spectr spectr = np.ravel(spectr) min_spec, max_spec = spectr.min(), spectr.max() pos = np.array([0., 0.25, 0.5, 0.75, 1.]) color = [[20, 133, 212, 255], [53, 42, 135, 255], [48, 174, 170, 255], [210, 184, 87, 255], [249, 251, 14, 255]] color = np.array(color, dtype=np.ubyte) cmap = qtg.ColorMap(pos, color) spectr = (spectr.astype(float) - min_spec) / (max_spec - min_spec) w = qtg.GraphicsWindow() w.setWindowTitle("Spectrogram of {}".format(G.__repr__(limit=4))) label = 'frequencies {}:{:.2f}:{:.2f}'.format(0, G.lmax/M, G.lmax) v = w.addPlot(labels={'bottom': 'nodes', 'left': label}) v.setAspectLocked() spi = qtg.ScatterPlotItem(np.repeat(np.arange(G.N), M), np.ravel(np.tile(np.arange(M), (1, G.N))), pxMode=False, symbol='s', size=1, brush=cmap.map(spectr, 'qcolor')) v.addItem(spi) global _qtg_windows _qtg_windows.append(w)