Linking one viewBox's X-axis with another viewBox's Y-axis

58 views
Skip to first unread message

Mark Semple

unread,
Dec 21, 2016, 12:45:41 PM12/21/16
to pyqtgraph
Hi there,

I have two PlotItem objects in a GraphicsLayoutWidget.
It is easy to link together their X-axes or Y-axes with the setXLink, setYLink, or LinkView methods.
But is it possible to link one viewBox's X-Axis with another's Y-Axis?

Thanks,

-Mark

Manu

unread,
Feb 11, 2020, 9:25:34 AM2/11/20
to pyqtgraph
Hi, I've got the same question. Any advice?

Patrick

unread,
Feb 11, 2020, 10:59:11 PM2/11/20
to pyqtgraph
Hi,

Connect to the signals of the plot's ViewBox and then sync the range changes manually. I have done this in the past for a four-panel display of a "3D cube" of data and it works well (see screenshot). Important parts of code looks like this:

    def __init__(self):
       
# ...
       
# overview, t1slice, t2slice, spectrum are pyqtgraph plots
       
# ...
       
self.overview.setYLink(self.t1slice)
       
self.overview.setXLink(self.t2slice)
       
self.t1slice.getViewBox().sigRangeChangedManually.connect(self._link_waxes_t1slice)
       
self.t2slice.getViewBox().sigRangeChangedManually.connect(self._link_waxes_t2slice)
       
self.spectrum.getViewBox().sigRangeChangedManually.connect(self._link_waxes_spectrum)

   
def _link_waxes_t1slice(self, something):
       
self.t2slice.setYRange(*self.t1slice.getViewBox().viewRange()[0])
       
self.spectrum.setXRange(*self.t1slice.getViewBox().viewRange()[0])

   
def _link_waxes_t2slice(self, something):
       
self.t1slice.setXRange(*self.t2slice.getViewBox().viewRange()[1])
       
self.spectrum.setXRange(*self.t2slice.getViewBox().viewRange()[1])

   
def _link_waxes_spectrum(self, something):
       
self.t1slice.setXRange(*self.spectrum.getViewBox().viewRange()[0])
       
self.t2slice.setYRange(*self.spectrum.getViewBox().viewRange()[0])

Patrick
Screenshot from 2020-02-12 14-24-09.png

Manu

unread,
Feb 12, 2020, 9:22:07 AM2/12/20
to pyqt...@googlegroups.com
Thanks very much, I can now link X axis of ViewBox1 to Y axis of ViewBox2. Also, thanks for your quick response!

However I noticed following bug: I have to quickly zoom in/out in each ViewBox to "initialize" the linking. Else when zooming (or translating) in ViewBox1, there is a strange wiggling in ViewBow2 (instead of also zooming in). The wiggling is like a very fast zoom in / zoom out. 
As a workaround, when initalizing my widget I do:
self.ViewBox1.scaleBy(1)
self.ViewBox2.scaleBy(1)
Which simulates the quick zoom in/out I had to do with the mouse. Now everything works as intended. But I find it strange that I had to do this to achieve desired behaviour. Did someone had a similar issue or can shed some light?





--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/f29d02ed-1a3d-425c-9966-4892b0c5207c%40googlegroups.com.

Patrick

unread,
Feb 12, 2020, 9:38:48 PM2/12/20
to pyqtgraph
Hi,

This is probably because the signals are only emitted on manual (user) changes of the view region. If you load/add data to the plots then the axes limits may change, but not trigger the synchronisation with the linked plot. There are other signals (http://www.pyqtgraph.org/documentation/_modules/pyqtgraph/graphicsItems/ViewBox/ViewBox.html#ViewBox) like sigXRangeChanged, but if you decide to connect to them instead you'll need to be careful not to trigger infinite loops. I have a method which resets axes limits and ranges etc which I call after loading data etc to do the initial sync of the axes, which would have a similar effect to what you have done. Otherwise you could manually call one of your change handlers when data is loaded/changes.

Patrick
To unsubscribe from this group and stop receiving emails from it, send an email to pyqt...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages