File: gen_example_imageitem_transform.py

package info (click to toggle)
python-pyqtgraph 0.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,168 kB
  • sloc: python: 54,831; makefile: 128; ansic: 40; sh: 2
file content (54 lines) | stat: -rw-r--r-- 1,664 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
generates 'example_false_color_image.png'
"""
import numpy as np
import pyqtgraph as pg
import pyqtgraph.exporters as exp
from pyqtgraph.Qt import QtGui, mkQApp

mkQApp("ImageItem transform example")

class MainWindow(pg.GraphicsLayoutWidget):
    """ example application main window """
    def __init__(self):
        super().__init__()
        self.resize(440,400)
        self.show()

        plot = self.addPlot()

        # Set To Larger Font
        leftAxis = plot.getAxis('left')
        bottomAxis = plot.getAxis('bottom')
        font = QtGui.QFont("Roboto", 18)
        leftAxis.setTickFont(font)
        bottomAxis.setTickFont(font)

        # Example: Transformed display of ImageItem
        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):
        exporter = exp.ImageExporter(self.scene())
        exporter.parameters()['width'] = 440
        exporter.export('example_imageitem_transform.png')

main_window = MainWindow()

if __name__ == '__main__':
    pg.exec()