# QwtSymbol

class qwt.symbol.QwtSymbol(*args)

  A class for drawing symbols

  Symbol styles:

  > - QwtSymbol.NoSymbol: No Style. The symbol cannot be drawn.

  > - QwtSymbol.Ellipse: Ellipse or circle

  > - QwtSymbol.Rect: Rectangle

  > - QwtSymbol.Diamond: Diamond

  > - QwtSymbol.Triangle: Triangle pointing upwards

  > - QwtSymbol.DTriangle: Triangle pointing downwards

  > - QwtSymbol.UTriangle: Triangle pointing upwards

  > - QwtSymbol.LTriangle: Triangle pointing left

  > - QwtSymbol.RTriangle: Triangle pointing right

  > - QwtSymbol.Cross: Cross (+)

  > - QwtSymbol.XCross: Diagonal cross (X)

  > - QwtSymbol.HLine: Horizontal line

  > - QwtSymbol.VLine: Vertical line

  > - QwtSymbol.Star1: X combined with +

  > - QwtSymbol.Star2: Six-pointed star

  > - QwtSymbol.Hexagon: Hexagon

  > - QwtSymbol.Path: The symbol is represented by a painter path, where the origin (0, 0) of the path coordinate system is mapped to the position of the symbol

  >   ..seealso:

  >       :py:meth:`setPath()`, :py:meth:`path()`

  > - QwtSymbol.Pixmap: The symbol is represented by a pixmap. The pixmap is centered or aligned to its pin point.

  >   ..seealso:

  >       :py:meth:`setPinPoint()`

  > - QwtSymbol.Graphic: The symbol is represented by a graphic. The graphic is centered or aligned to its pin point.

  >   ..seealso:

  >       :py:meth:`setPinPoint()`

  > - QwtSymbol.SvgDocument: The symbol is represented by a SVG graphic. The graphic is centered or aligned to its pin point.

  >   ..seealso:

  >       :py:meth:`setPinPoint()`

  > - QwtSymbol.UserStyle: Styles >= QwtSymbol.UserStyle are reserved for derived classes of QwtSymbol that overload drawSymbols() with additional application specific symbol types.

  Cache policies:

  > Depending on the render engine and the complexity of the symbol shape it might be faster to render the symbol to a pixmap and to paint this pixmap.

  > F.e. the raster paint engine is a pure software renderer where in cache mode a draw operation usually ends in raster operation with the the backing store, that are usually faster, than the algorithms for rendering polygons. But the opposite can be expected for graphic pipelines that can make use of hardware acceleration.

  > The default setting is AutoCache

  > ..seealso:

  >     :py:meth:`setCachePolicy()`, :py:meth:`cachePolicy()`

  > Note

  > The policy has no effect, when the symbol is painted to a vector graphics format (PDF, SVG).

  > Warning

  > Since Qt 4.8 raster is the default backend on X11

  > Valid cache policies:

  > > - QwtSymbol.NoCache: Don’t use a pixmap cache

  > > - QwtSymbol.Cache: Always use a pixmap cache

  > > - QwtSymbol.AutoCache: Use a cache when the symbol is rendered with the software renderer (QPaintEngine.Raster)

  class QwtSymbol([style=QwtSymbol.NoSymbol])

    The symbol is constructed with gray interior, black outline with zero width, no size and style ‘NoSymbol’.

    Parameters:

      style (int) – Symbol Style

  class QwtSymbol(style, brush, pen, size)
    Parameters:

      - style (int) – Symbol Style

      - brush (QBrush) – Brush to fill the interior

      - pen (QPen) – Outline pen

      - size (QSize) – Size

  class QwtSymbol(path, brush, pen)
    Parameters:

      - path (QPainterPath) – Painter path

      - brush (QBrush) – Brush to fill the interior

      - pen (QPen) – Outline pen

  See also

  `setPath()`, `setBrush()`, `setPen()`, `setSize()`

  Style

    alias of `int`

  classmethod make(style=None, brush=None, pen=None, size=None, path=None, pixmap=None, graphic=None, svgdocument=None, pinpoint=None)

    Create and setup a new QwtSymbol object (convenience function).

    Parameters:

      - style (int or None) – Symbol Style

      - brush (QBrush or None) – Brush to fill the interior

      - pen (QPen or None) – Outline pen

      - size (QSize or None) – Size

      - path (QPainterPath or None) – Painter path

      - path – Painter path

      - pixmap (QPixmap or None) – Pixmap as symbol

      - graphic (qwt.graphic.QwtGraphic or None) – Graphic

      - svgdocument – SVG icon as symbol

    See also

    `setPixmap()`, `setGraphic()`, `setPath()`

  setCachePolicy(policy)

    Change the cache policy

    The default policy is AutoCache

    Parameters:

      policy (int) – Cache policy

    See also

    `cachePolicy()`

  cachePolicy()
    Returns:

      Cache policy

    See also

    `setCachePolicy()`

  setPath(path)

    Set a painter path as symbol

    The symbol is represented by a painter path, where the origin (0, 0) of the path coordinate system is mapped to the position of the symbol.

    When the symbol has valid size the painter path gets scaled to fit into the size. Otherwise the symbol size depends on the bounding rectangle of the path.

    The following code defines a symbol drawing an arrow:

        from qtpy.QtGui import QApplication, QPen, QPainterPath, QTransform
        from qtpy.QtCore import Qt, QPointF
        from qwt import QwtPlot, QwtPlotCurve, QwtSymbol
        import numpy as np

        app = QApplication([])

        # --- Construct custom symbol ---

        path = QPainterPath()
        path.moveTo(0, 8)
        path.lineTo(0, 5)
        path.lineTo(-3, 5)
        path.lineTo(0, 0)
        path.lineTo(3, 5)
        path.lineTo(0, 5)

        transform = QTransform()
        transform.rotate(-30.0)
        path = transform.map(path)

        pen = QPen(Qt.black, 2 );
        pen.setJoinStyle(Qt.MiterJoin)

        symbol = QwtSymbol()
        symbol.setPen(pen)
        symbol.setBrush(Qt.red)
        symbol.setPath(path)
        symbol.setPinPoint(QPointF(0., 0.))
        symbol.setSize(10, 14)

        # --- Test it within a simple plot ---

        curve = QwtPlotCurve()
        curve_pen = QPen(Qt.blue)
        curve_pen.setStyle(Qt.DotLine)
        curve.setPen(curve_pen)
        curve.setSymbol(symbol)
        x = np.linspace(0, 10, 10)
        curve.setData(x, np.sin(x))

        plot = QwtPlot()
        curve.attach(plot)
        plot.resize(600, 300)
        plot.replot()
        plot.show()

        app.exec_()

    Parameters:

      path (QPainterPath) – Painter path

    See also

    `path()`, `setSize()`

  path()
    Returns:

      Painter path for displaying the symbol

    See also

    `setPath()`

  setPixmap(pixmap)

    Set a pixmap as symbol

    Parameters:

      pixmap (QPixmap) – Pixmap

    See also

    `pixmap()`, `setGraphic()`

    Note

    The style() is set to QwtSymbol.Pixmap

    Note

    brush() and pen() have no effect

  pixmap()
    Returns:

      Assigned pixmap

    See also

    `setPixmap()`

  setGraphic(graphic)

    Set a graphic as symbol

    Parameters:

      graphic (qwt.graphic.QwtGraphic) – Graphic

    See also

    `graphic()`, `setPixmap()`

    Note

    The style() is set to QwtSymbol.Graphic

    Note

    brush() and pen() have no effect

  graphic()
    Returns:

      Assigned graphic

    See also

    `setGraphic()`

  setSvgDocument(svgDocument)

    Set a SVG icon as symbol

    Parameters:

      svgDocument – SVG icon

    See also

    `setGraphic()`, `setPixmap()`

    Note

    The style() is set to QwtSymbol.SvgDocument

    Note

    brush() and pen() have no effect

  setSize(*args)

    Specify the symbol’s size

    setSize(width[, height=-1])
      Parameters:

        - width (int) – Width

        - height (int) – Height

    setSize(size)
      Parameters:

        size (QSize) – Size

    See also

    `size()`

  size()
    Returns:

      Size

    See also

    `setSize()`

  setBrush(brush)

    Assign a brush

    The brush is used to draw the interior of the symbol.

    Parameters:

      brush (QBrush) – Brush

    See also

    `brush()`

  brush()
    Returns:

      Brush

    See also

    `setBrush()`

  setPen(*args)

    Build and/or assign a pen, depending on the arguments.

    setPen(color, width, style)

      Build and assign a pen

      In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it non cosmetic (see QPen.isCosmetic()). This method signature has been introduced to hide this incompatibility.

      Parameters:

        - color (QColor) – Pen color

        - width (float) – Pen width

        - style (Qt.PenStyle) – Pen style

    setPen(pen)

      Assign a pen

      Parameters:

        pen (QPen) – New pen

    See also

    `pen()`, `brush()`

  pen()
    Returns:

      Pen

    See also

    `setPen()`, `brush()`

  setColor(color)

    Set the color of the symbol

    Change the color of the brush for symbol types with a filled area. For all other symbol types the color will be assigned to the pen.

    Parameters:

      color (QColor) – Color

    See also

    `setPen()`, `setBrush()`, `brush()`, `pen()`

  setPinPoint(pos, enable=True)

    Set and enable a pin point

    The position of a complex symbol is not always aligned to its center ( f.e an arrow, where the peak points to a position ). The pin point defines the position inside of a Pixmap, Graphic, SvgDocument or PainterPath symbol where the represented point has to be aligned to.

    Parameters:

      pos (QPointF) – Position

    Enable bool enable:

      En/Disable the pin point alignment

    See also

    `pinPoint()`, `setPinPointEnabled()`

  pinPoint()
    Returns:

      Pin point

    See also

    `setPinPoint()`, `setPinPointEnabled()`

  setPinPointEnabled(on)

    En/Disable the pin point alignment

    Parameters:

      on (bool) – Enabled, when on is true

    See also

    `setPinPoint()`, `isPinPointEnabled()`

  isPinPointEnabled()
    Returns:

      True, when the pin point translation is enabled

    See also

    `setPinPoint()`, `setPinPointEnabled()`

  drawSymbols(painter, points)

    Render an array of symbols

    Painting several symbols is more effective than drawing symbols one by one, as a couple of layout calculations and setting of pen/brush can be done once for the complete array.

    Parameters:

      - painter (QPainter) – Painter

      - points (QPolygonF) – Positions of the symbols in screen coordinates

  drawSymbol(painter, point_or_rect)

    Draw the symbol into a rectangle

    The symbol is painted centered and scaled into the target rectangle. It is always painted uncached and the pin point is ignored.

    This method is primarily intended for drawing a symbol to the legend.

    Parameters:

      - painter (QPainter) – Painter

      - point_or_rect (QPointF or QPoint or QRectF) – Position or target rectangle of the symbol in screen coordinates

  renderSymbols(painter, points)

    Render the symbol to series of points

    Parameters:

      - painter (QPainter) – Painter

      - point_or_rect – Positions of the symbols

  boundingRect()

    Calculate the bounding rectangle for a symbol at position (0,0).

    Returns:

      Bounding rectangle

  invalidateCache()

    Invalidate the cached symbol pixmap

    The symbol invalidates its cache, whenever an attribute is changed that has an effect ob how to display a symbol. In case of derived classes with individual styles (>= QwtSymbol.UserStyle) it might be necessary to call invalidateCache() for attributes that are relevant for this style.

    See also

    `setCachePolicy()`, `drawSymbols()`

  setStyle(style)

    Specify the symbol style

    Parameters:

      style (int) – Style

    See also

    `style()`

  style()
    Returns:

      Current symbol style

    See also

    `setStyle()`