Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Demonstrates very basic use of ImageItem to display image data inside a ViewBox.
"""
## Add path to library (just for examples; you do not need this)
import initExample
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pyqtgraph as pg
import pyqtgraph.ptime as ptime
app = QtGui.QApplication([])
## Create window with GraphicsView widget
win = pg.GraphicsLayoutWidget()
win.show() ## show widget alone in its own window
win.setWindowTitle('pyqtgraph example: ImageItem')
view = win.addViewBox()
## lock the aspect ratio so pixels are always square
view.setAspectLocked(True)
## Create image item
img = pg.ImageItem(border='w')
view.addItem(img)
## Set initial view bounds
view.setRange(QtCore.QRectF(0, 0, 600, 600))
## Create random image
data = np.random.normal(size=(15, 600, 600), loc=1024, scale=64).astype(np.uint16)
def init_plt( self ) :
# Initialize the "GraphicsLayoutWidget" for this widget. This
# will allow a grid of "GraphicsItem" objects, which will
# include the plots themselves, the axes, and the axis labels.
# Note. The "QGridLayout" object given to this widget as its
# layout is essentially a dummy. I tried to just having
# this widget be an extention of "GraphicsLayoutWidget"
# (i.e., having it inheret that type), but I couldn't get
# it to display anything at all.
self.setLayout( QGridLayout( ) )
self.grd = GraphicsLayoutWidget( )
self.grd.setBackground( 'w' )
self.layout( ).addWidget( self.grd )
self.layout().setContentsMargins( 0, 0, 0, 0 )
# Initialize the text for the x- and y-axis labels. Then,
# create the labels themselves and add them to the grid.
self.txt_axs_x = 'Time [s]'
self.txt_axs_y = 'Magnetic Field [nT]'
if ( self.core.app.res_lo ) :
size = '8pt'
else :
size = '10pt'
def create_display_widget(self):
self._display_widget = QtWidgets.QFrame(self)
self._display_layout = QtWidgets.QVBoxLayout()
self._display_layout.setContentsMargins(0, 0, 0, 0)
self.img_layout_widget = GraphicsLayoutWidget()
self.img_widget = MaskImgWidget(self.img_layout_widget)
self._display_layout.addWidget(self.img_layout_widget)
self._status_layout = QtWidgets.QHBoxLayout()
self._status_layout.addSpacerItem(HorizontalSpacerItem())
self.pos_lbl = LabelAlignRight('')
self._status_layout.addWidget(self.pos_lbl)
self._display_layout.addLayout(self._status_layout)
self._display_widget.setLayout(self._display_layout)
def __init__(self, *args, **kwargs):
super(CalibrationDisplayWidget, self).__init__(*args, **kwargs)
self._layout = QtWidgets.QVBoxLayout(self)
self._layout.setContentsMargins(0, 0, 0, 0)
self.img_layout_widget = GraphicsLayoutWidget()
self.cake_layout_widget = GraphicsLayoutWidget()
self.pattern_layout_widget = GraphicsLayoutWidget()
self.img_widget = MaskImgWidget(self.img_layout_widget)
self.cake_widget = CalibrationCakeWidget(self.cake_layout_widget)
self.pattern_widget = PatternWidget(self.pattern_layout_widget)
self.tab_widget = QtWidgets.QTabWidget()
self.tab_widget.addTab(self.img_layout_widget, 'Image')
self.tab_widget.addTab(self.cake_layout_widget, 'Cake')
self.tab_widget.addTab(self.pattern_layout_widget, 'Pattern')
self._layout.addWidget(self.tab_widget)
self._status_layout = QtWidgets.QHBoxLayout()
self.calibrate_btn = FlatButton("Calibrate")
self.refine_btn = FlatButton("Refine")
self.position_lbl = QtWidgets.QLabel("position_lbl")
def __init__(self, sandbox, *args, **kwargs):
pg.GraphicsLayoutWidget.__init__(self, **kwargs)
self.sandbox = sandbox
self.plots = [
DisplacementPlot(
sandbox,
title='Scene Displacement',
component=lambda m: m.reference.scene.displacement),
DisplacementPlot(
sandbox,
title='Model Residual',
component=lambda m: m.reference.difference)]
self.plots[-1].addHintText()
self._mov_sig = pg.SignalProxy(
self.scene().sigMouseMoved,
rateLimit=60, slot=self.mouseMoved)
def init_figure(self):
"""Init figures"""
self.canvas2d_cartesian = pg.GraphicsLayoutWidget()
self.canvas2d_polar = pg.GraphicsLayoutWidget()
self.canvas3d = gl.GLViewWidget()
self.canvas3d_array = pg.GraphicsLayoutWidget()
self.ui.layout_canvas.addWidget(self.canvas3d)
self.ui.layout_canvas.addWidget(self.canvas3d_array)
self.ui.layout_canvas.addWidget(self.canvas2d_cartesian)
self.ui.layout_canvas.addWidget(self.canvas2d_polar)
self.plot_type_changed(self.ui.cb_plottype.currentIndex())
"""Surface view"""
self.cmap = cm.get_cmap('jet')
self.minZ = -100
self.maxZ = 0
self.surface_plot = gl.GLSurfacePlotItem(computeNormals=False)
return int(self.UI.dilate_kernelX_spinbox.value())
@property
def dilate_kernelY(self):
return int(self.UI.dilate_kernelY_spinbox.value())
@property
def dilate_iters(self):
return int(self.UI.dilate_iters_spinbox.value())
@property
def num_largest_components(self):
return int(self.UI.n_largest_component_spinbox.value())
class QImshow(pg.GraphicsLayoutWidget):
emitter = pyqtSignal(object)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.emitter.connect(lambda x: self.update_figure(x))
self._view = self.addViewBox()
self._view.setAspectLocked(True)
self._img = pg.ImageItem(border='w')
self._view.addItem(self._img)
self._view.setRange(QRectF(0, 0, 128, 128))
self.lock = time.time()
self.fps = 25
self.freq = 1/self.fps
def draw_buffer(self):
self.buff_win = pg.GraphicsLayoutWidget()
self.buff_win.setWindowTitle('Buffer Status')
self.buff_win.resize(800, 700)
self.total_peers = self.number_of_monitors + self.number_of_peers + self.number_of_malicious
self.p4 = self.buff_win.addPlot()
self.p4.showGrid(x=True, y=True, alpha=100) # To show grid lines across x axis and y axis
leftaxis = self.p4.getAxis('left') # get left axis i.e y axis
leftaxis.setTickSpacing(5, 1) # to set ticks at a interval of 5 and grid lines at 1 space
# Get different colors using matplotlib library
if self.total_peers < 8:
colors = cm.Set2(np.linspace(0, 1, 8))
elif self.total_peers < 12:
colors = cm.Set3(np.linspace(0, 1, 12))
else:
colors = cm.rainbow(np.linspace(0, 1, self.total_peers+1))
def init_figure(self):
"""Init figures"""
self.canvas2d_cartesian = pg.GraphicsLayoutWidget()
self.canvas2d_polar = pg.GraphicsLayoutWidget()
self.canvas3d = gl.GLViewWidget()
self.canvas3d_array = pg.GraphicsLayoutWidget()
self.ui.layout_canvas.addWidget(self.canvas3d)
self.ui.layout_canvas.addWidget(self.canvas3d_array)
self.ui.layout_canvas.addWidget(self.canvas2d_cartesian)
self.ui.layout_canvas.addWidget(self.canvas2d_polar)
self.plot_type_changed(self.ui.cb_plottype.currentIndex())
"""Surface view"""
self.cmap = cm.get_cmap('jet')
self.minZ = -100
self.maxZ = 0
self.overlay_graphicsView_03.setFrameShape(QtGui.QFrame.NoFrame)
self.overlay_graphicsView_03.setAlignment(QtCore.Qt.AlignCenter)
self.overlay_graphicsView_03.setObjectName(_fromUtf8("overlay_graphicsView_03"))
self.overlay_graphicsView_08 = GraphicsLayoutWidget(self.overlays_groupBox)
self.overlay_graphicsView_08.setGeometry(QtCore.QRect(220, 285, 192, 64))
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.overlay_graphicsView_08.sizePolicy().hasHeightForWidth())
self.overlay_graphicsView_08.setSizePolicy(sizePolicy)
self.overlay_graphicsView_08.setMinimumSize(QtCore.QSize(192, 64))
self.overlay_graphicsView_08.setMaximumSize(QtCore.QSize(192, 64))
self.overlay_graphicsView_08.setFrameShape(QtGui.QFrame.NoFrame)
self.overlay_graphicsView_08.setAlignment(QtCore.Qt.AlignCenter)
self.overlay_graphicsView_08.setObjectName(_fromUtf8("overlay_graphicsView_08"))
self.overlay_graphicsView_05 = GraphicsLayoutWidget(self.overlays_groupBox)
self.overlay_graphicsView_05.setGeometry(QtCore.QRect(10, 200, 192, 64))
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.overlay_graphicsView_05.sizePolicy().hasHeightForWidth())
self.overlay_graphicsView_05.setSizePolicy(sizePolicy)
self.overlay_graphicsView_05.setMinimumSize(QtCore.QSize(192, 64))
self.overlay_graphicsView_05.setMaximumSize(QtCore.QSize(192, 64))
self.overlay_graphicsView_05.setFrameShape(QtGui.QFrame.NoFrame)
self.overlay_graphicsView_05.setAlignment(QtCore.Qt.AlignCenter)
self.overlay_graphicsView_05.setObjectName(_fromUtf8("overlay_graphicsView_05"))
self.overlay_graphicsView_02 = GraphicsLayoutWidget(self.overlays_groupBox)
self.overlay_graphicsView_02.setGeometry(QtCore.QRect(220, 30, 192, 64))
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)