コード例 #1
0
ファイル: points.py プロジェクト: asirinelli/veusz
def plotMarkers(painter, xpos, ypos, markername, markersize, scaling=None,
                clip=None):
    """Funtion to plot an array of markers on a painter.

    painter: QPainter
    xpos, ypos: iterable item of positions
    markername: name of marker from MarkerCodes
    markersize: size of marker to plot
    scaling: scale size of markers by array, or don't in None
    clip: rectangle if clipping wanted
    """

    # minor optimization
    if markername == 'none':
        return
    
    painter.save()

    # get sharper angles and more exact positions using these settings
    pen = painter.pen()
    pen.setJoinStyle( qt4.Qt.MiterJoin )
    painter.setPen(pen)

    # get path to draw and whether to fill
    path, fill = getPainterPath(painter, markername, markersize)
    if not fill:
        # turn off brush
        painter.setBrush( qt4.QBrush() )

    # split up into two loops as this is a critical path
    if scaling is None:
        plotPathsToPainter(painter, path, xpos, ypos, clip)
    else:
        # plot markers, scaling each one
        s = painter.scale
        t = painter.translate
        d = painter.drawPath
        r = painter.resetTransform
        for x, y, sc in izip(xpos, ypos, scaling):
            t(x, y)
            s(sc, sc)
            d(path)
            r()
    
    painter.restore()
コード例 #2
0
ファイル: points.py プロジェクト: JoonyLi/veusz
def plotMarkers(painter, xpos, ypos, markername, markersize, scaling=None,
                clip=None, cmap=None, colorvals=None):
    """Funtion to plot an array of markers on a painter.

    painter: QPainter
    xpos, ypos: iterable item of positions
    markername: name of marker from MarkerCodes
    markersize: size of marker to plot
    scaling: scale size of markers by array, or don't in None
    clip: rectangle if clipping wanted
    cmap: colormap to use if colorvals is set
    colorvals: color values 0-1 of each point if used
    """

    # minor optimization
    if markername == 'none':
        return
    
    painter.save()

    # get sharper angles and more exact positions using these settings
    pen = painter.pen()
    pen.setJoinStyle( qt4.Qt.MiterJoin )
    painter.setPen(pen)

    # get path to draw and whether to fill
    path, fill = getPainterPath(painter, markername, markersize)
    if not fill:
        # turn off brush
        painter.setBrush( qt4.QBrush() )

    # if using colored points
    colorimg = None
    if colorvals is not None:
        # convert colors to rgb values via a 2D image and pass to function
        trans = (1-painter.brush().color().alphaF())*100
        color2d = colorvals.reshape( 1, len(colorvals) )
        colorimg = colormap.applyColorMap(
            cmap, 'linear', color2d, 0., 1., trans)

    # this is the fast (C++) or slow (python) helper
    plotPathsToPainter(painter, path, xpos, ypos, scaling, clip, colorimg)

    painter.restore()