bottom viewbox on PlotWidget and legend issues

38 views
Skip to first unread message

dhabbyc

unread,
Aug 2, 2018, 11:42:28 PM8/2/18
to pyqtgraph
Hello,

 I have a PlotWidget on which I have added a ViewBox instance on the bottom of the layout. The idea is to place the legend there.

 So far I have two issues:

  1. The legend box doesnt fit the viewbox height... No matter what I do... I've tried to force the box size, to set manually the widget geometry and nothing works...
  2. I havent been able to "center" the legend below the main plot. When I try to manually set the position of it (setPos) i cant compute correctly the appropiate coordinates. If I use the viewbox center minus the coordinates of the center of the legend, the result is biased to the left.

Here is an example of what I'm doing:

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

app = QtGui.QApplication([])
mw = QtGui.QMainWindow()

cw = QtGui.QWidget()
mw.setCentralWidget(cw)
l = QtGui.QVBoxLayout()
cw.setLayout(l)
pw = pg.PlotWidget(name='Plot1')
l.addWidget(pw)

vb = pg.ViewBox(parent = pw.plotItem)

pw.plotItem.layout.addItem(vb, 4, 1, 1, 4)

lg = pg.LegendItem()
lg.setParentItem(vb)



curve = pg.PlotCurveItem(y = np.random.normal(size=100)*1e0)
pw.plotItem.addItem(curve)
lg.addItem(curve, 'test')

mw.show()


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

 Thanks in advance.

D.
Reply all
Reply to author
Forward
0 new messages