Is antialiasing for 2D plots with OpenGL not supported?

192 views
Skip to first unread message

Alexander Huszagh

unread,
Feb 28, 2016, 8:04:36 PM2/28/16
to pyqtgraph
Hi,

I'm a scientific researcher plotting profiles with 10k, 100k, maybe 1 million + points, which means 2D plots with high point density. We can also stack these plots to get large data sizes.

I've been using the QtOpenGL extensions quite successfully for the 2D plots, which seems independent of PyOpenGL (since I use Ubuntu, and the system-wide version does not install correctly from the package manager), especially with large datasets, along with the clipToView parameter. I was wondering, however, if antialiasing was supported at all for 2D plots with OpenGL, if this is specifically limited within the package due to hardware, or globally disabled.

For background, here is my default plotting arguments (although done within a PlotWidget, so pg.plot becomes self.plot, and the xRange and yRange would be defined).

import pyqtgraph as pg
x
= np.arange(1000)
y
= x**2
pg
.plot(x, y, antialias=True, clipToView=True)

I then was looking at why antialiasing did not occur when OpenGL was set to True. I tried to manually override it, with:

pw = pg.PlotWidget()
pw.setAntialiasing(True)

And inside pyqtgraph/widgets/graphicsview.py, in setAntialiasing (starting on line 132), I modified the method from:

    def setAntialiasing(self, aa):
        """Enable or disable default antialiasing.
        Note that this will only affect items that do not specify their own antialiasing options."""

        if aa:
            self.setRenderHints(self.renderHints() | QtGui.QPainter.Antialiasing)
        else:
            self.setRenderHints(self.renderHints() & ~QtGui.QPainter.Antialiasing)


to

    def setAntialiasing(self, aa):
        """Enable or disable default antialiasing.
        Note that this will only affect items that do not specify their own antialiasing options."""

        if aa and isinstance(self.viewport(), QtOpenGL.QGLWidget):
            self.viewport().context().format().setSampleBuffers(True)

        if aa:
            self.setRenderHints(self.renderHints() | QtGui.QPainter.Antialiasing)
        else:
            self.setRenderHints(self.renderHints() & ~QtGui.QPainter.Antialiasing)

I verified that this correctly set the sample buffers for the PlotWidget (by checking self.viewport().context().format().sampleBuffers()), however, this did not change the antialiasing within the actual plot.

So, I went to the PlotCurveItem and modified the paint method (starting on line 411), from:


       
    def paint(self, p, opt, widget):
       ...
       p.setRenderHint(p.Antialiasing, aa)
           
       ...

to

       
    def paint(self, p, opt, widget):
       ...
       p.setRenderHint(p.Antialiasing, aa)
       if aa and isinstance(widget, QtOpenGL.QGLWidget):
           widget.context().format().setSampleBuffers(True)
       ...

However, very quickly I noticed that this did not actually set sampleBuffers to True (it was still False), but if I used widget.context().setFormat(QtOpenGL.QGLFormat(QtOpenGL.GL.SampleBuffers), that the format would be invalid.

So with that background, my question is: Does PyQtGraph support antialiasing with OpenGL? It seems my architecture does not support spatial sample buffering with OpenGL, and is the lack of antialiasing could just be sample buffering being automatically disabled by PyQtGraph or Qt to avoid producing an invalid QGLFormat. Is this the case, is there any other steps I could do to use antialiasing with OpenGL?

If not, this is a minor concern. I've been very pleased with the PyQtGraph for realtime plotting.

Thanks,
Alex

Alexander Huszagh

unread,
Feb 28, 2016, 8:09:38 PM2/28/16
to pyqtgraph
 I should probably also add that I am using PyQtGraph version 0.9.10, am using the PySide backends, and have a Nvidia GeForce GPU on Ubuntu (using Nvidia drivers), if this helps at all.

Stefan Kuczera

unread,
May 17, 2017, 11:07:36 AM5/17/17
to pyqtgraph
Any news here? Opengl and antialias together would be nice.
Reply all
Reply to author
Forward
0 new messages