Question

I am drawing a plot with pyqtgraph:

wave = pg.PlotWidget(self, QtGui.QColor(0, 0, 0, 0))
wave.plot([1,2,3], [1,2,1], pen=(0,0,255), fillLevel=-0, brush=(255,215,0))

I'd like to get the pixel coordinates of the last point (3,1)

How can I do that?

Was it helpful?

Solution

Qt makes it simple to map between coordinate systems with its QGraphicsItem.map* methods. PyQtGraph further extends these with even more pg.GraphicsItem.map* methods. The one you want works like this:

>>> import pyqtgraph as pg
>>> plt = pg.plot()
>>> wave = plt.plot([1,2,3], [1,2,1])
>>> wave.mapToDevice(pg.Point(3, 1))
PyQt4.QtCore.QPointF(615.6409081308565, 438.7833653023292)`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top