Invert Y-Axis on pg.ImageView

1,098 views
Skip to first unread message

volker....@inqbus.de

unread,
Jun 7, 2015, 6:48:16 PM6/7/15
to pyqt...@googlegroups.com

Hello !

Currently I am evaluating Python graphics packages for use in an interactive LIDAR data analysis code.

I am new to pyqtgraph. To my first impression it is very promissing. Lots of examples, short code, easy installation, fast.

I need a 2d-plot of a time x counts 2d-matrix.


app = QtGui.QApplication([])
win = QtGui.QMainWindow()
win.resize(800,800)
imv = pg.ImageView()
win.setCentralWidget(imv)
win.show()
imv.setImage( m.signals.chan_5.data)

where m.signals.chan_5.data is

>>> m.signals.chan_5.data
array([[0, 1, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       ...,
       [1, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0]], dtype=int32)
>>> m.signals.chan_5.data.shape
(713, 6400)

This gives me the desired plot but upside down.

There is a "transform" parameter for the setImage function

def setImage(self, img, autoRange=True, autoLevels=True, levels=None, axes=None, xvals=None, pos=None, scale=None, transform=None, autoHistogramRange=True):

* Can this parameter be used to invert the Y-Axis? I found no documentation on the transformation possibilities.
* Whats the best practice?

All pointers welcome

Volker


Message has been deleted

L. Smash

unread,
Jun 8, 2015, 4:52:02 AM6/8/15
to pyqt...@googlegroups.com
Hey,

I don't know any specific function to invert the y-axis in pg.ImageView. There is a short description of the "transform" parameter here. It changes pos and scale, so I don't think you can invert the y-axis with this.
If you can use a viewbox, there is a invertY-function:

view = win.addViewBox(lockAspect=True)

view.invertY(True)


Otherwise you can try it this way:


imv.setImage(your_2Darray[:,::-1])


Lars

anonymou...@gmail.com

unread,
Jun 9, 2015, 10:06:43 PM6/9/15
to pyqt...@googlegroups.com
I think here you actually have to call invertY(False):

#in original question
imv
.setImage( m.signals.chan_5.data)
imv
.view.invertY(False)

Looking inside ImageView.py, by default it creates for itself a ViewBox view and by default calls view.invertY() already.
Looking inside ViewBox.py, invertY() proceeds only if the requested inversion is different from current state of inversion.
So here you un-invert it with invertY(False)

volker....@inqbus.de

unread,
Jun 12, 2015, 7:29:49 PM6/12/15
to pyqt...@googlegroups.com
Sorry for the long delay!

With your help I solved the first obstacle on my way.

Currently I am diggin into pyqtgraph and I like it. It's not perfect, but usable and the code is ok..
The code documentation is weak, but the examples are a good starting point.

There is no competitor left in the field - and we will use PyQtGraph for the graphical components of our project.

Cheers

Volker



john lunzer

unread,
Jun 15, 2015, 7:06:47 AM6/15/15
to pyqt...@googlegroups.com
I think what you said sums up perfectly my thoughts about pyqtgraph:

Not perfect but very usable, sparse documentation, helpful examples, no competition for performance or Qt integrated graphing.
Reply all
Reply to author
Forward
0 new messages