0

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?

Fra
  • 4,918
  • 7
  • 33
  • 50

1 Answers1

2

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)`
Luke
  • 11,374
  • 2
  • 48
  • 61
  • Thanks. What if I wanted to get the coordinates of the last point in the plot? How do I access it from the wave variable? – Fra May 13 '14 at 21:47
  • `wave.getData()` returns the last displayed point (taking into account the downsampling and clipping options in use). Otherwise, you can access the raw data as `wave.curve.xData` and `.yData`. – Luke May 13 '14 at 22:56