TextItems and axis range behave strangely when reducing window height

35 views
Skip to first unread message

nvdw

unread,
Jan 4, 2017, 8:27:00 AM1/4/17
to pyqtgraph
Hi,

The example code below adds a TextItem next to each data point in the plot. At runtime, I manually reduce the height of the window, which results in an updated range for the Y-axis. However, upon further reducing the height of the window, the Y-axis range suddenly starts to rapidly cycle through ever-increasing negative numbers. And this cycling does not stop, until one increases the window height again.

This behavior only occurs when TextItems are present in the plot. Hence, one hypothesis is that the fixed height of the font of the TextItem leads to some cyclic behavior of when setting the range of the axis.

I found some similarities with what was reported by another user here:
The issue was never solved/understood, only side-stepped.

Are there any suggestions on how to prevent this cycling of the Y-axis range when reducing the window height?

Here is the code (pyqtgraph 0.10, pyqt 4.11):

from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg

app = QtGui.QApplication([])

win = pg.GraphicsWindow()

p1 = pg.PlotItem(y=np.random.normal(size=100))
win.addItem(p1)

curve = p1.curves[0]
for x, y in zip(curve.xData, curve.yData):
marker = pg.TextItem("W")
marker.setPos(x, y)
p1.addItem(marker)

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

Bill Eaton

unread,
Jun 6, 2019, 2:11:18 PM6/6/19
to pyqtgraph
This is an old thread, but I recently encountered this problem myself.

If you look at the code in the TextItem example that comes with pyqtgraph, they call setPos() after plot.addItem(), so your code would change

FROM
    marker = pg.TextItem("W")
marker.setPos(x, y)
p1.addItem(marker)

TO
    marker = pg.TextItem("W")
    p1.addItem(marker)
marker.setPos(x, y)
Reply all
Reply to author
Forward
0 new messages