Example #1
0
# -*- coding: utf-8 -*-
"""

Description of example


"""
import initExample  ## Add path to library (just for examples; you do not need this)

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui, mkQApp
import numpy as np

app = mkQApp()

# win.setWindowTitle('pyqtgraph example: ____')

## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()
Example #2
0
            lambda i, j: (1 + 0.3 * np.sin(i)) * (i)**2 + (j)**2, (100, 100))
        noisy_data = data * (1 + 0.2 * np.random.random(data.shape))

        # Example: False color image with interactive level adjustment
        img = pg.ImageItem(image=noisy_data
                           )  # create monochrome image from demonstration data
        plot.addItem(img)  # add to PlotItem 'plot'
        cm = pg.colormap.get('CET-L9')  # prepare a linear color map
        bar = pg.ColorBarItem(values=(0, 20_000),
                              cmap=cm)  # prepare interactive color bar
        # Have ColorBarItem control colors of img and appear in 'plot':
        bar.setImageItem(img, insert_in=plot)

        self.timer = pg.QtCore.QTimer(singleShot=True)
        self.timer.timeout.connect(self.export)
        self.timer.start(100)

    def export(self):
        print('exporting')
        exporter = exp.ImageExporter(self.scene())
        exporter.parameters()['width'] = 420
        exporter.export('example_false_color_image.png')


mkQApp("False color image example")
main_window = MainWindow()

## Start Qt event loop
if __name__ == '__main__':
    mkQApp().exec_()
Example #3
0
            lambda i, j: (1 + 0.3 * np.sin(i)) * (i)**2 + (j)**2, (100, 100))
        noisy_data = data * (1 + 0.2 * np.random.random(data.shape))

        # Example: False color image with interactive level adjustment
        img = pg.ImageItem(image=noisy_data
                           )  # create monochrome image from demonstration data
        plot.addItem(img)  # add to PlotItem 'plot'
        cm = pg.colormap.get('CET-L9')  # prepare a linear color map
        bar = pg.ColorBarItem(values=(0, 20_000),
                              cmap=cm)  # prepare interactive color bar
        # Have ColorBarItem control colors of img and appear in 'plot':
        bar.setImageItem(img, insert_in=plot)

        self.timer = pg.QtCore.QTimer(singleShot=True)
        self.timer.timeout.connect(self.export)
        self.timer.start(100)

    def export(self):
        print('exporting')
        exporter = exp.ImageExporter(self.scene())
        exporter.parameters()['width'] = 420
        exporter.export('example_false_color_image.png')


mkQApp("False color image example")
main_window = MainWindow()

## Start Qt event loop
if __name__ == '__main__':
    pg.exec()
Example #4
0
        p3 = gr_wid.addPlot(0, 1, 1, 1, title="shared 1")
        p3.addItem(i3)

        i4 = pg.ImageItem(image=noisy_transposed)
        p4 = gr_wid.addPlot(1, 1, 1, 1, title="shared 2")
        p4.addItem(i4)

        cmap = pg.colormap.get('CET-L8')
        bar = pg.ColorBarItem(
            # values = (-15_000, 15_000),
            limits=(-30_000, 30_000),  # start with full range...
            rounding=1000,
            width=10,
            colorMap=cmap)
        bar.setImageItem([i3, i4])
        bar.setLevels(low=-5_000,
                      high=15_000)  # ... then adjust to retro sunset.

        # manually adjust reserved space at top and bottom to align with plot
        bar.getAxis('bottom').setHeight(21)
        bar.getAxis('top').setHeight(31)
        gr_wid.addItem(bar, 0, 2, 2, 1)  # large bar spanning both rows


mkQApp("ColorBarItem Example")
main_window = MainWindow()

## Start Qt event loop
if __name__ == '__main__':
    pg.exec()
Example #5
0
        if self.mean_dt is None:
            self.mean_dt = dt
        else:
            self.mean_dt = 0.95 * self.mean_dt + 0.05 * dt # average over fluctuating measurements
        self.top_plot.setTitle(
            'refresh: {:0.1f}ms -> {:0.1f} fps'.format( 1000*self.mean_dt, 1/self.mean_dt )
        )
        # handle rolling buffer:
        self.last_update = timestamp
        for dic in self.traces:
            new_data = dic['ds'].get_data( timestamp )
            idx_a = dic['ptr']
            idx_b = idx_a + len( new_data )
            len_buffer = dic['buf'].shape[0]
            if idx_b < len_buffer: # data does not cross buffer boundary
                dic['buf'][idx_a:idx_b] = new_data
            else: # part of the new data needs to roll over to beginning of buffer
                len_1 = len_buffer - idx_a # this many elements still fit
                dic['buf'][idx_a:idx_a+len_1] = new_data[:len_1] # first part of data at end
                idx_b = len(new_data) - len_1
                dic['buf'][0:idx_b] = new_data[len_1:] # second part of data at re-start
            dic['ptr'] = idx_b
            dic['crv'].setData( dic['buf'] )

mkQApp("Gradient plotting example")
main_window = MainWindow()

## Start Qt event loop
if __name__ == '__main__':
    pg.exec()
Example #6
0
# -*- coding: utf-8 -*-
"""
Very basic 3D graphics example; create a view widget and add a few items.

"""
## Add path to library (just for examples; you do not need this)
import initExample

from pyqtgraph.Qt import QtCore, QtGui, mkQApp
import pyqtgraph.opengl as gl

app = mkQApp("GLViewWidget Example")
w = gl.GLViewWidget()
w.opts['distance'] = 20
w.show()
w.setWindowTitle('pyqtgraph example: GLViewWidget')

ax = gl.GLAxisItem()
ax.setSize(5, 5, 5)
w.addItem(ax)

b = gl.GLBoxItem()
w.addItem(b)

ax2 = gl.GLAxisItem()
ax2.setParentItem(b)

b.translate(1, 1, 1)

if __name__ == '__main__':
    pg.mkQApp().exec_()
Example #7
0
    def gradientChanged():
        global volume, volumeItem, gradientEditor, levels
        indices = np.nonzero(volume == 0)
        listTicks = gradientEditor.listTicks()
        listTicks[0][0].color.setAlpha(0)
        for tick in listTicks[1:]:
            tick[0].color.setAlpha(30)
        lut = gradientEditor.getLookupTable(255)
        volumeColors = np.asarray([
            makeRGBA(data=slice, lut=lut, levels=levels)[0] for slice in volume
        ])
        # volumeColors[indices, 3] = 0
        volumeItem.setData(volumeColors)

    mkQApp()
    mainWindow = loadUi("UI/volume_visualization.ui")

    volumeItem = GLVolumeItem(None, sliceDensity=5)
    volumeItem.scale(*[voxelSize] * 3)
    gradientEditor = GradientEditorItem(orientation='right')
    gradientEditor.sigGradientChangeFinished.connect(gradientChanged)
    mainWindow.graphicsView.addItem(gradientEditor)
    volumeViewWidget = mainWindow.openGLWidget
    volumeViewWidget.addItem(volumeItem)

    volumeViewWidget.setCameraPosition(distance=volumeSize[0] * 3)
    volumeViewWidget.pan(*volumeSize / 2)

    space_box = GLBoxItem()
    space_box.setSize(*volumeSize)
Example #8
0
            self.mean_dt = 0.95 * self.mean_dt + 0.05 * dt  # average over fluctuating measurements
        self.top_plot.setTitle('refresh: {:0.1f}ms -> {:0.1f} fps'.format(
            1000 * self.mean_dt, 1 / self.mean_dt))
        # handle rolling buffer:
        self.last_update = timestamp
        for dic in self.traces:
            new_data = dic['ds'].get_data(timestamp)
            idx_a = dic['ptr']
            idx_b = idx_a + len(new_data)
            len_buffer = dic['buf'].shape[0]
            if idx_b < len_buffer:  # data does not cross buffer boundary
                dic['buf'][idx_a:idx_b] = new_data
            else:  # part of the new data needs to roll over to beginning of buffer
                len_1 = len_buffer - idx_a  # this many elements still fit
                dic['buf'][
                    idx_a:idx_a +
                    len_1] = new_data[:len_1]  # first part of data at end
                idx_b = len(new_data) - len_1
                dic['buf'][0:idx_b] = new_data[
                    len_1:]  # second part of data at re-start
            dic['ptr'] = idx_b
            dic['crv'].setData(dic['buf'])


mkQApp("Gradient plotting example")
main_window = MainWindow()

## Start Qt event loop
if __name__ == '__main__':
    mkQApp().exec_()
Example #9
0
        tr = QtGui.QTransform().translate(-0.5, -0.5) 
        correlogram.setTransform(tr)
        correlogram.setImage(corrMatrix)

        plotItem = gr_wid.addPlot()      # add PlotItem to the main GraphicsLayoutWidget
        plotItem.invertY(True)           # orient y axis to run top-to-bottom
        plotItem.setDefaultPadding(0.0)  # plot without padding data range
        plotItem.addItem(correlogram)    # display correlogram
        
        # show full frame, label tick marks at top and left sides, with some extra space for labels:
        plotItem.showAxes( True, showValues=(True, True, False, False), size=20 )

        # define major tick marks and labels:
        ticks = [ (idx, label) for idx, label in enumerate( columns ) ]
        for side in ('left','top','right','bottom'):
            plotItem.getAxis(side).setTicks( (ticks, []) ) # add list of major ticks; no minor ticks
        plotItem.getAxis('bottom').setHeight(10) # include some additional space at bottom of figure

        colorMap = pg.colormap.get("CET-D1")     # choose perceptually uniform, diverging color map
        # generate an adjustabled color bar, initially spanning -1 to 1:
        bar = pg.ColorBarItem( values=(-1,1), cmap=colorMap) 
        # link color bar and color map to correlogram, and show it in plotItem:
        bar.setImageItem(correlogram, insert_in=plotItem)    

mkQApp("Correlation matrix display")
main_window = MainWindow()

## Start Qt event loop
if __name__ == '__main__':
    pg.exec()
Example #10
0
        tr = QtGui.QTransform()  # prepare ImageItem transformation:
        tr.scale(6.0, 3.0)  # scale horizontal and vertical axes
        tr.translate(-1.5,
                     -1.5)  # move 3x3 image to locate center at axis origin

        img = pg.ImageItem(image=np.eye(3),
                           levels=(0, 1))  # create example image
        img.setTransform(tr)  # assign transform

        plot.addItem(img)  # add ImageItem to PlotItem
        plot.showAxes(True)  # frame it with a full set of axes
        plot.invertY(True)  # vertical axis counts top to bottom

        self.timer = pg.QtCore.QTimer(singleShot=True)
        self.timer.timeout.connect(self.export)
        self.timer.start(100)

    def export(self):
        print('exporting')
        exporter = exp.ImageExporter(self.scene())
        exporter.parameters()['width'] = 420
        exporter.export('example_imageitem_transform.png')


mkQApp("ImageItem transform example")
main_window = MainWindow()

## Start Qt event loop
if __name__ == '__main__':
    pg.exec()
Example #11
0
        #--- multiple images adjusted by a separate color bar ------------------------
        i3 = pg.ImageItem(image=noisy_data)
        p3 = gr_wid.addPlot(0,1, 1,1, title="shared 1")
        p3.addItem( i3 )

        i4 = pg.ImageItem(image=noisy_transposed)
        p4 = gr_wid.addPlot(1,1, 1,1, title="shared 2")
        p4.addItem( i4 )

        cmap = pg.colormap.get('CET-L8')
        bar = pg.ColorBarItem(
            # values = (-15_000, 15_000),
            limits = (-30_000, 30_000), # start with full range...
            rounding=1000,
            width = 10,
            cmap=cmap )
        bar.setImageItem( [i3, i4] )
        bar.setLevels( low=-5_000, high=15_000) # ... then adjust to retro sunset.

        # manually adjust reserved space at top and bottom to align with plot
        bar.getAxis('bottom').setHeight(21)
        bar.getAxis('top').setHeight(31)
        gr_wid.addItem(bar, 0,2, 2,1) # large bar spanning both rows

mkQApp("ColorBarItem Example")
main_window = MainWindow()

## Start Qt event loop
if __name__ == '__main__':
    mkQApp().exec_()
Example #12
0
"""
Simple examples demonstrating the use of GLTextItem.

"""

import pyqtgraph as pg
import pyqtgraph.opengl as gl
from pyqtgraph.Qt import mkQApp

app = mkQApp("GLTextItem Example")

gvw = gl.GLViewWidget()
gvw.show()
gvw.setWindowTitle('pyqtgraph example: GLTextItem')

griditem = gl.GLGridItem()
griditem.setSize(10, 10)
griditem.setSpacing(1, 1)
gvw.addItem(griditem)

axisitem = gl.GLAxisItem()
gvw.addItem(axisitem)

txtitem1 = gl.GLTextItem(pos=(0.0, 0.0, 0.0), text='text1')
gvw.addItem(txtitem1)

txtitem2 = gl.GLTextItem()
txtitem2.setData(pos=(1.0, -1.0, 2.0),
                 color=(127, 255, 127, 255),
                 text='text2')
gvw.addItem(txtitem2)
def qapp():
    app = mkQApp()
    if app is None:
        app = mkQApp()
    yield app
    app.processEvents(QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 100)