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:
- 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...
- 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.