I'm currently using pg.ArrowItem to mark certain events on the plot. However, this is quite slow when there are many items. Is there a faster way to draw points, rectangles, circles on a chart.
import pyqtgraph as pgplt = pg.plot()sp = pg.ScatterPlotItem()plt.addItem(sp)
# Make an arrow path, rotated 45 degreestr = pg.QtGui.QTransform()tr.rotate(-45)arrow = tr.map(pg.makeArrowPath(headLen=0.25, tailLen=0.25, tipAngle=40, tailWidth=0.07))
# Fill the scatter plot with datasp.setData( x=[.1,.2,.3,.4,.5,.6,.7,.8], y=[.1,.3,.2,.4,.3,.5,.4,.6], symbol=['o', '+', 't', 'd', 's', arrow, arrow, arrow], size=[10, 10, 10, 20, 20, 30, 40, 50])In the long term my plan is to phase out QGraphicsView in favor of an entirely OpenGL-based system. This will take a lot of work, though, since QGraphicsView provides a lot of functionality that will be difficult to replace. I'm working with the developers of a few other graphics libraries to build a common system to fill this need.
In the long term my plan is to phase out QGraphicsView in favor of an entirely OpenGL-based system. This will take a lot of work, though, since QGraphicsView provides a lot of functionality that will be difficult to replace. I'm working with the developers of a few other graphics libraries to build a common system to fill this need.This sounds pretty interesting. Any information on the web about this common system? Incidentally, have you seen galry (https://github.com/rossant/galry)?
Cyrille (of Galry) is actively participating in the project. There is a placeholder for the project here: http://code.google.com/p/pyvis3d but we're really still just in the discussion phase.
I get the following error when using the scatterplotitem.Traceback (most recent call last):size=[10, 10, 10, 20, 20, 30, 40, 50])File "/pyqtgraph/graphicsItems/ScatterPlotItem.py", line 293, in setDataself.addPoints(*args, **kargs)File "/pyqtgraph/graphicsItems/ScatterPlotItem.py", line 387, in addPointssetMethod(kargs[k], update=False, dataSet=newData, mask=kargs.get('mask', None))File "/pyqtgraph/graphicsItems/ScatterPlotItem.py", line 498, in setSizeif kargs['mask'] is not None:NameError: global name 'kargs' is not defined
I frequently have large timeseries data sets (>10,000 samples) and using other tools (MATLAB for example) I will sometimes plot the line as well as points. I don't have a need for any specific shape, just a point indicating the location of each data point. So far, using the ScatterPlotItem (typically by using the symbol argument to PlotItem's plot method) seems to drastically slow down performance of the plot. My thought is that using QPoint would speed things up but before digging into the source to figure out exactly how to implement that, I wanted to get your input. Is there a good way to speed this up? Maybe I'm overlooking something.
I worked out a solution to this using ctypes to directly access the Qt library to call QPainter.drawPoints; see the attached script. It is able to comfortably draw 1e6 points on my machine at about 15 fps. It probably still needs some work (I haven't tested on windows or OSX yet, and there may be some version-specific differences to check for).I suspect this method could also be used to speed up the pixmap fragment painting for scatterPlotItem..Thanks for pushing me to keep thinking about this :)Luke
Traceback (most recent call last):
File "pointsTest.py", line 9, in <module>
drawPoints = getattr(qtlib, '?drawPoints@QPainter@@QEAAXPEBVQPointF@@H@Z')
File "C:\Python27\lib\ctypes\__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "C:\Python27\lib\ctypes\__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function '?drawPoints@QPainter@@QEAAXPEBVQPointF@@H@Z' not found
On Mon, May 6, 2013 at 1:45 PM, Luke M <lcj...@gmail.com> wrote:
On Friday, May 3, 2013 12:01:03 AM UTC-4, Luke Campagnola wrote:I worked out a solution to this using ctypes to directly access the Qt library to call QPainter.drawPoints; see the attached script. It is able to comfortably draw 1e6 points on my machine at about 15 fps. It probably still needs some work (I haven't tested on windows or OSX yet, and there may be some version-specific differences to check for).I suspect this method could also be used to speed up the pixmap fragment painting for scatterPlotItem..Thanks for pushing me to keep thinking about this :)LukeThanks for looking into it. This sounds good. Unfortunately, I just got a chance to try this out and I get the following error on line 9:
Traceback (most recent call last):File "pointsTest.py", line 9, in <module>
drawPoints = getattr(qtlib, '?draw...@QPainter@@QEAAXPEBVQPointF@@H@Z')
File "C:\Python27\lib\ctypes\__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "C:\Python27\lib\ctypes\__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function '?draw...@QPainter@@QEAAXPEBVQPointF@@H@Z' not found
Would this be a PyQt version issue? I'm still on 4.9.1, mostly because I don't have admin rights on my PC to update...
It could very well be. One of the drawbacks to using ctypes is that I need to know the exact function names that the DLL exports, and these names may change between versions and platforms. I used 'dependency walker' (http://www.dependencywalker.com) to find the function name in C:\python27\lib\site-packages\pyqt4\qtgui4.dllIf you can find the name on your system, I'll add it to the list..Luke
File "pointsTest.py", line 44, in paintdrawPoints(ptr, self.data.ctypes, self.data.shape[0])WindowsError: exception: access violation reading 0x00000001
On Mon, May 6, 2013 at 2:29 PM, Luke M <lcj...@gmail.com> wrote:
On Monday, May 6, 2013 1:54:55 PM UTC-4, Luke Campagnola wrote:On Mon, May 6, 2013 at 1:45 PM, Luke M <lcj...@gmail.com> wrote:On Friday, May 3, 2013 12:01:03 AM UTC-4, Luke Campagnola wrote:I worked out a solution to this using ctypes to directly access the Qt library to call QPainter.drawPoints; see the attached script. It is able to comfortably draw 1e6 points on my machine at about 15 fps. It probably still needs some work (I haven't tested on windows or OSX yet, and there may be some version-specific differences to check for).I suspect this method could also be used to speed up the pixmap fragment painting for scatterPlotItem..Thanks for pushing me to keep thinking about this :)LukeThanks for looking into it. This sounds good. Unfortunately, I just got a chance to try this out and I get the following error on line 9:drawPoints = getattr(qtlib, '?draw...@QPainter@@QEAAXPEBVQPointF@@H@Z')Traceback (most recent call last):File "pointsTest.py", line 9, in <module>AttributeError: function '?draw...@QPainter@@QEAAXPEBVQPointF@@H@Z' not found
File "C:\Python27\lib\ctypes\__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "C:\Python27\lib\ctypes\__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
Would this be a PyQt version issue? I'm still on 4.9.1, mostly because I don't have admin rights on my PC to update...It could very well be. One of the drawbacks to using ctypes is that I need to know the exact function names that the DLL exports, and these names may change between versions and platforms. I used 'dependency walker' (http://www.dependencywalker.com) to find the function name in C:\python27\lib\site-packages\pyqt4\qtgui4.dllIf you can find the name on your system, I'll add it to the list..Luke
I found it at '?draw...@QPainter@@QAEXPBVQPointF@@H@Z', though it was different on my XP machine with 4.9.1 so there seems to be some other factor.
Anyway, now I'm getting another error:File "pointsTest.py", line 44, in paintdrawPoints(ptr, self.data.ctypes, self.data.shape[0])WindowsError: exception: access violation reading 0x00000001
That's strange. Are either of the pointers actually equal to 0x1? (ptr or self.data.ctypes.data)Luke
ptr: c_void_p(2213320)
data.ctypes: <numpy.core._internal._ctypes object at 0x04780F30>
...
from ctypes.util import find_library
if sys.platform == 'win32':
qtlib = ctypes.windll.qtgui4
drawPoints = getattr(qtlib, '?drawPoints@QPainter@@QEAAXPEBVQPointF@@H@Z')
else:
qtlib = ctypes.cdll.LoadLibrary(find_library("QtGui"))
drawPoints = getattr(qtlib, '_ZN8QPainter10drawPointsEPK7QPointFi')
class PointsItem(QtGui.QGraphicsItem):
....drawRects = getattr(qtlib, '_ZN12QPaintEngine9drawRectsEPK6QRectFi')
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/201327c8-e094-4631-abeb-e3506760a0ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Luke,
sorry, I think I did not write properly in my question, actually I already got this part,but I don't know how to use the drawRect function inside the painter function.Normally I can just pass drawRect( int x, int y, int width, int height )but with the ctypes and sip inside, I'm not sure how can I adapt this for drawRect