Hi Luke,
The code below displays LegendItem on the the side, extending the example you have given. How can the legend be moved to the right top corner of the window? Right now, it shows on the bottom right, below the bottom axis, and is not fully visible? It seems to me, I don't understand Qt enough to make it work...
My last try was like this: (it is also in the code below, commented out)
legend.setPos(legend.mapFromItem(legend, QtCore.QPointF(675,38)))
but unfortunatelly, it does not move the legend...
from PyQt4 import QtGui
import pyqtgraph as pg
from PyQt4 import QtCore
win = pg.GraphicsWindow()
plot = win.addPlot()
curve1 = plot.plot([1,3,2,4], pen='r', name='red plot')
curve2 = plot.plot([1, 2, 2.5], [3, 4, 3], pen='g', name='green plot')
vb = win.addViewBox()
legend = pg.LegendItem()
vb.addItem(legend)
legend.addItem(curve1, name=curve1.opts['name'])
legend.addItem(curve2, name=curve2.opts['name'])
## legend.setPos(legend.mapFromItem(legend, QtCore.QPointF(675,38)))
vb.setMaximumWidth(legend.boundingRect().width() + 10) # get legend.boundingRect() after items have been added
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
Thanks,
Jure