Possible bug, GraphicsLayoutWidget

40 views
Skip to first unread message

Dominic Wilson

unread,
Oct 2, 2020, 9:14:03 AM10/2/20
to pyqtgraph

Plots with scientific notation on the ylabel appear smaller than other plots in a GraphicsLayoutWidget after using setData.

In the example below, the width of the first column shrinks after setting the data in each plot.

from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import random

app = QtGui.QApplication([])
# create layout and add 4 plots to it in 2x2 grid
win = pg.GraphicsLayoutWidget(show=True)
win.showMaximized()
plots = []
for i in range(2):
    for j in range(2):
        plots.append(win.addPlot())
    win.nextRow()

# create plotdataitem for each plot
lines = [p.plot() for p in plots]


# add random data, with 1 plot much larger range than the rest
def update():
    lines[0].setData(range(100), [random.gauss(1e7, 1e5) for i in range(100)])
    for line in lines[1:4]:
        line.setData(range(100), [random.gauss(0, 1) for i in range(100)])


# update()
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(2000)
app.exec_()




ixjl...@gmail.com

unread,
Oct 3, 2020, 1:31:39 PM10/3/20
to pyqtgraph
I suspect this is related https://github.com/pyqtgraph/pyqtgraph/issues/1187

I'm concerned this is some Qt behavior that would be tricky to work around, but I haven't gotten a chance to look into it much. One idea for a workaround would be to use a LayoutWidget with separate PlotWidgets inside, so changing your example to something like this:


win = pg.LayoutWidget()

win.showMaximized()
plots = []
for i in range(2):
    for j in range(2):
        pw = pg.PlotWidget()
        win.addWidget(pw)
        plots.append(pw)
    win.nextRow()
Reply all
Reply to author
Forward
0 new messages