XLinked PlotItem issue

55 views
Skip to first unread message

pojzn

unread,
Aug 22, 2018, 5:16:26 AM8/22/18
to pyqtgraph

Hello everyone,

I have posted about a problem I'm experiencing when trying to link multiple plots via setXLink, described here.
Any ideas or suggestions will be greatly appreciated.

Thank you in advance!

Lior Weintraub

unread,
Aug 22, 2018, 6:43:47 AM8/22/18
to pyqtgraph
Hi Pojzn,

I don't know the solution to your problem (actually I never used the cool feature of link before).
Thought it would help you know I tried your example on my side and it worked fine.
My setup is Win7 with Anaconda3 (installed latest version of pyqtgraph).
Regards,
Lee.

Patrick

unread,
Aug 22, 2018, 11:34:59 PM8/22/18
to pyqtgraph
Hi,

There's definitely a bug. The linking of view ranges is working fine, but it is about the drawing of the axes and labels obviously. I don't have a solution, but here are some initial thoughts that might help.

First, I think the top 2x2 grid arrangement has the same problem -- it's not just limited to the vertical stack. Also, I don't think linking of the axes has anything to do with it either, it just makes it more noticeable since there's more plots to see the issue on. The same text drawing issue can happen on a single plot as well.

The problem is the text is allowed to draw outside of the axes range, but then that region is not being erased when the axes are resized and new labels are painted. I don't understand the intricacies of the layout of the labels and their width/height boxes to see how or why, but I'm guessing it's an issue in the generateDrawSpecs method of AxisItem (http://www.pyqtgraph.org/documentation/_modules/pyqtgraph/graphicsItems/AxisItem.html#AxisItem.generateDrawSpecs).

I think there might be some floating point rounding errors that make two text labels get drawn at the same tick, and then they overlap. Workaround is to not zoom in that much! :) Seriously though, limit the zoom range to avoid this, since your data can't be stored/plotted with that much precision anyway.

Just to demonstrate, here is the modified example with the axes label widths in the 2x2 grid plot fixed, so there's no resizing, but the labels can still spill out of their allocated box (most noticeable around where the "A" autoscale button lives). The vertical stack is no longer a stack, just a single plot, but you can get the same issue happening.

from PyQt5.QtWidgets import QMainWindow, QWidget, QGridLayout
from pyqtgraph import ViewBox, PlotItem
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg

app = QtGui.QApplication([])

window = QMainWindow()
holder = QWidget()
holder_layout = QGridLayout()
holder.setLayout(holder_layout)
window.setCentralWidget(holder)

#
# Grid section
#
grid_widget = pg.GraphicsLayoutWidget()
grid_subplot1 = grid_widget.addPlot(col=0, row=0)
grid_subplot2 = grid_widget.addPlot(col=1, row=0)
grid_subplot3 = grid_widget.addPlot(col=0, row=1)
grid_subplot4 = grid_widget.addPlot(col=1, row=1)
for plotitem in (grid_subplot1, grid_subplot2, grid_subplot3, grid_subplot4):
    plotitem.setRange(xRange=(0, 5), yRange=(0, 2.5), padding=0)
    plotitem.showGrid(True, True, 0.2)
    plotitem.getAxis('left').setStyle(autoExpandTextSpace=False, tickTextWidth=40)
#
# Grid XLink 1->2,2->3,3-4
#
grid_subplot1.setXLink(grid_subplot2)
grid_subplot2.setXLink(grid_subplot3)
grid_subplot3.setXLink(grid_subplot4)
#
# Vertical section
#
vertical_widget = pg.GraphicsLayoutWidget()
vertical_subplot1 = vertical_widget.addPlot(col=0, row=0)
vertical_subplot1.setRange(xRange=(0, 5), yRange=(0, 2.5), padding=0)
vertical_subplot1.showGrid(True, True, 0.2)

holder_layout.addWidget(grid_widget)
holder_layout.addWidget(vertical_widget)


if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        window.show()
        QtGui.QApplication.instance().exec_()


And a screenshot from above example to show text spilling out to the left of the x-axis, and the two labels on same tick. Better to play with the demo, but it's a start:

Screenshot from 2018-08-23 12-50-52.png


Patrick
Reply all
Reply to author
Forward
0 new messages