def paint(self, p, *args):

        #p.setPen(fn.mkPen('r'))
        #p.drawRect(self.boundingRect())

        if self._exportOpts is not False:
            aa = self._exportOpts.get('antialias', True)
            scale = self._exportOpts.get('resolutionScale', 1.0)  ## exporting to image; pixel resolution may have changed
        else:
            aa = self.opts['antialias']
            scale = 1.0

        if self.opts['pxMode'] is True:
            p.resetTransform()

            # Map point coordinates to device
            pts = np.vstack([self.data['x'], self.data['y']])
            pts = self.mapPointsToDevice(pts)
            if pts is None:
                return

            # Cull points that are outside view
            viewMask = self.getViewMask(pts)
            #pts = pts[:,mask]
            #data = self.data[mask]

            if self.opts['useCache'] and self._exportOpts is False:
                # Draw symbols from pre-rendered atlas
                atlas = self.fragmentAtlas.getAtlas()

                # Update targetRects if necessary
                updateMask = viewMask & np.equal(self.data['targetRect'], None)
                if np.any(updateMask):
                    updatePts = pts[:,updateMask]
                    width = self.data[updateMask]['width']*2
                    self.data['targetRect'][updateMask] = list(imap(QtCore.QRectF, updatePts[0,:], updatePts[1,:], width, width))

                data = self.data[viewMask]
                if USE_PYSIDE or USE_PYQT5:
                    list(imap(p.drawPixmap, data['targetRect'], repeat(atlas), data['sourceRect']))
                else:
                    p.drawPixmapFragments(data['targetRect'].tolist(), data['sourceRect'].tolist(), atlas)
            else:
                # render each symbol individually
                p.setRenderHint(p.Antialiasing, aa)

                data = self.data[viewMask]
                pts = pts[:,viewMask]
                for i, rec in enumerate(data):
                    p.resetTransform()
                    p.translate(pts[0,i] + rec['width'], pts[1,i] + rec['width'])
                    drawSymbol(p, *self.getSpotOpts(rec, scale))
        else:
            if self.picture is None:
                self.picture = QtGui.QPicture()
                p2 = QtGui.QPainter(self.picture)
                for rec in self.data:
                    if scale != 1.0:
                        rec = rec.copy()
                        rec['size'] *= scale
                    p2.resetTransform()
                    p2.translate(rec['x'], rec['y'])
                    drawSymbol(p2, *self.getSpotOpts(rec, scale))
                p2.end()

            p.setRenderHint(p.Antialiasing, aa)
            self.picture.play(p)