Share axis between ImageView and PlotWidget

693 views
Skip to first unread message

klo uo

unread,
Jul 19, 2014, 11:53:06 PM7/19/14
to pyqt...@googlegroups.com
Hi,

I layout two rows - ImageView and PlotWidget.

In PlotWidget I plot a function that shares same x-axis with ImageView - i.e the function returns some data about each pixel column in horizontal direction.
I want to link both axis. `pw.setXLink(iv)` doesn't work, as ImageView axis is missing some method.

Is it possible to link plot x-axis with image x-axis, while still using ImageView widget?
Or is there some different way to accomplish same task?

Jim Passmore

unread,
Jul 20, 2014, 12:55:37 AM7/20/14
to pyqt...@googlegroups.com
A while back I asked a similar question here: https://groups.google.com/d/topic/pyqtgraph/35BJ1zfBWRo/discussion

See Luke's answer, where he suggested to use a ViewBox with an ImageItem inside, instead of an ImageView.  I was able to make mine work using that approach, linking axes with PlotItems.  Hope this helps.

Jim

Luke Campagnola

unread,
Jul 22, 2014, 11:09:35 AM7/22/14
to pyqt...@googlegroups.com
On Sat, Jul 19, 2014 at 11:53 PM, klo uo <klo...@gmail.com> wrote:
In PlotWidget I plot a function that shares same x-axis with ImageView - i.e the function returns some data about each pixel column in horizontal direction.
I want to link both axis. `pw.setXLink(iv)` doesn't work, as ImageView axis is missing some method.

Is it possible to link plot x-axis with image x-axis, while still using ImageView widget?
Or is there some different way to accomplish same task?

You just need to link the plot to the internal viewbox of the ImageView widget:

    plt = pg.PlotWidget()
    iv = pg.ImageView()
    plt.setXLink(iv.view)

Jim's suggestion is also a valid approach.

klo uo

unread,
Jul 22, 2014, 3:03:24 PM7/22/14
to pyqt...@googlegroups.com
Thanks, that's great, as I wanted to use ImageView widget

If I may take one more related question about widgets size: I have this code:

========================================
l = QtGui.QGridLayout()

iv = pg.ImageView()
l.addWidget(iv, 0, 0, 3, 1)

pw = pg.PlotWidget()
pw.setXLink(iv.view)
l.addWidget(pw, 1, 0, 1, 1)
========================================

expecting it would size top widget across 3 rows and bottom widget on 1 row, but it's not happens.

I tried using `addWidget(pw, 1, 0, rowspan=3, colspan=1), but the command does not understand these parameters


klo uo

unread,
Jul 22, 2014, 7:11:53 PM7/22/14
to pyqt...@googlegroups.com

There is `pw.setMaximumHeight()` method, so i.e. setting `pw.setMaximumHeight(100)` draws fixed height plot widget.
There is `pw.setFixedHeight()` too.

Luke Campagnola

unread,
Jul 23, 2014, 1:24:36 PM7/23/14
to pyqt...@googlegroups.com
Rows and columns do not have a fixed size in Qt, so having a widget occupy more rows does not cause it to have a larger size. You control the relative sizes of widgets either by setting the size of the widgets themselves (via QWidget.setSizePolicy, setFixedSize, setMaximumSize, etc) or by making suggesting to the layout (via QGridLayout.setRowStretch, setRowMinimumHeight, etc.)

Reply all
Reply to author
Forward
0 new messages