pyqtgraph, how track log/linear axes transformation changes between linked axes

1.1k views Asked by At

I have 3 linked views, linked by X axis. This works great. However, when I switch one plot to log X mode, the others do not switch to log x mode, but they pop in to zoom way in to the log version of the x axis.

How do it make it so the log X transformation applies to all plots? So far, I simply use the code

diViewWidget.setXLink(frViewWidget)
noiseViewWidget.setXLink(diViewWidget)

The data should look like this:

but actually look like this:

Basically, to reproduce you can go to any 2 linked views, right click and set the transformation to log x.

The workaround I found is to go to each plot individually and set the transformation individually, but I'd like it to happen programatically.

Thanks,

-Caleb

2

There are 2 answers

1
custeg cestug On BEST ANSWER
#learning qt i just found a better linkLogXChecks version

from itertools import permutations
def linkLogXChecks(plotitems):
    for a, b in permutations(plotitems, 2):
        a.ctrl.logXCheck.toggled.connect(b.ctrl.logXCheck.setChecked)
0
custeg cestug On

https://groups.google.com/forum/#!msg/pyqtgraph/3686qqVHgpI/bmBAQ_sDKJIJ https://forum.qt.io/topic/39241/how-to-set-logarithmic-scale-on-a-qgraphicsview/2 I couldn't apply that fix across separate PlotItems, so tried broadcasting the changed checkbox signal and it seems to work

import pyqtgraph as pg

data = pg.np.random.normal(size=100)

app = pg.QtGui.QApplication([])
win = pg.GraphicsWindow()
p1 = win.addPlot(y=data)

win.nextRow()
p2 = win.addPlot(y=data)
p2.setXLink(p1)

win.nextRow()
p3 = win.addPlot(y=data)
p3.setXLink(p1)


def linkLogXChecks(plotitems):
    def broadcast(state):
        for p in plotitems:
            p.ctrl.logXCheck.setChecked(state)
    for p in plotitems:
        p.ctrl.logXCheck.toggled.connect(broadcast)

linkLogXChecks([p1, p2, p3])


pg.QtGui.QApplication.instance().exec_()