How to get the pixel coordinates of a plot line in pyqtgraph

落爺英雄遲暮 提交于 2019-12-11 19:51:34

问题


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?


回答1:


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)`


来源:https://stackoverflow.com/questions/23639781/how-to-get-the-pixel-coordinates-of-a-plot-line-in-pyqtgraph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!