QwtSymbol

class qwt.symbol.QwtSymbol(*args)[source]

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 qwt.symbol.QwtSymbol(style, brush, pen, size)[source]
Parameters:
  • style (int) – Symbol Style
  • brush (QBrush) – Brush to fill the interior
  • pen (QPen) – Outline pen
  • size (QSize) – Size
class qwt.symbol.QwtSymbol(path, brush, pen)[source]
Parameters:
  • path (QPainterPath) – Painter path
  • brush (QBrush) – Brush to fill the interior
  • pen (QPen) – Outline pen

See also

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

QwtSymbol.Style

alias of int

QwtSymbol.setCachePolicy(policy)[source]

Change the cache policy

The default policy is AutoCache

Parameters:policy (int) – Cache policy

See also

cachePolicy()

QwtSymbol.cachePolicy()[source]
Returns:Cache policy

See also

setCachePolicy()

QwtSymbol.setPath(path)[source]

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 qwt.qt.QtGui import QApplication, QPen, QPainterPath, QTransform
from qwt.qt.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_()            
../_images/symbol_path_example.png
Parameters:path (QPainterPath) – Painter path

See also

path(), setSize()

QwtSymbol.path()[source]
Returns:Painter path for displaying the symbol

See also

setPath()

QwtSymbol.setPixmap(pixmap)[source]

Set a pixmap as symbol

Parameters:pixmap (QPixmap) – Pixmap

Note

The style() is set to QwtSymbol.Pixmap

Note

brush() and pen() have no effect

QwtSymbol.pixmap()[source]
Returns:Assigned pixmap

See also

setPixmap()

QwtSymbol.setGraphic(graphic)[source]

Set a graphic as symbol

Parameters:graphic (qwt.graphic.QwtGraphic) – Graphic

Note

The style() is set to QwtSymbol.Graphic

Note

brush() and pen() have no effect

QwtSymbol.graphic()[source]
Returns:Assigned graphic

See also

setGraphic()

QwtSymbol.setSvgDocument(svgDocument)[source]

Set a SVG icon as symbol

Parameters:svgDocument – SVG icon

Note

The style() is set to QwtSymbol.SvgDocument

Note

brush() and pen() have no effect

QwtSymbol.setSize(*args)[source]

Specify the symbol’s size

setSize(width[, height=-1])[source]
Parameters:
  • width (int) – Width
  • height (int) – Height
setSize(size)[source]
Parameters:size (QSize) – Size

See also

size()

QwtSymbol.size()[source]
Returns:Size

See also

setSize()

QwtSymbol.setBrush(brush)[source]

Assign a brush

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

Parameters:brush (QBrush) – Brush

See also

brush()

QwtSymbol.brush()[source]
Returns:Brush

See also

setBrush()

QwtSymbol.setPen(*args)[source]

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

setPen(color, width, style)[source]

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)[source]

Assign a pen

Parameters:pen (QPen) – New pen

See also

pen(), brush()

QwtSymbol.pen()[source]
Returns:Pen

See also

setPen(), brush()

QwtSymbol.setColor(color)[source]

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
QwtSymbol.setPinPoint(pos, enable=True)[source]

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
QwtSymbol.pinPoint()[source]
Returns:Pin point
QwtSymbol.setPinPointEnabled(on)[source]

En/Disable the pin point alignment

Parameters:on (bool) – Enabled, when on is true
QwtSymbol.isPinPointEnabled()[source]
Returns:True, when the pin point translation is enabled
QwtSymbol.drawSymbols(painter, points, numPoints=None)[source]

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
QwtSymbol.drawSymbol(painter, point_or_rect)[source]

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
QwtSymbol.renderSymbols(painter, points, numPoints=None)[source]

Render the symbol to series of points

Parameters:
  • painter (QPainter) – Painter
  • point_or_rect – Positions of the symbols
QwtSymbol.boundingRect()[source]

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

Returns:Bounding rectangle
QwtSymbol.invalidateCache()[source]

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.

QwtSymbol.setStyle(style)[source]

Specify the symbol style

Parameters:style (int) – Style

See also

style()

QwtSymbol.style()[source]
Returns:Current symbol style

See also

setStyle()

class qwt.symbol.QwtSymbol(*args)[source]

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 qwt.symbol.QwtSymbol(style, brush, pen, size)[source]
Parameters:
  • style (int) – Symbol Style
  • brush (QBrush) – Brush to fill the interior
  • pen (QPen) – Outline pen
  • size (QSize) – Size
class qwt.symbol.QwtSymbol(path, brush, pen)[source]
Parameters:
  • path (QPainterPath) – Painter path
  • brush (QBrush) – Brush to fill the interior
  • pen (QPen) – Outline pen

See also

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

QwtSymbol.Style

alias of int

QwtSymbol.setCachePolicy(policy)[source]

Change the cache policy

The default policy is AutoCache

Parameters:policy (int) – Cache policy

See also

cachePolicy()

QwtSymbol.cachePolicy()[source]
Returns:Cache policy

See also

setCachePolicy()

QwtSymbol.setPath(path)[source]

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 qwt.qt.QtGui import QApplication, QPen, QPainterPath, QTransform
from qwt.qt.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_()            
../_images/symbol_path_example.png
Parameters:path (QPainterPath) – Painter path

See also

path(), setSize()

QwtSymbol.path()[source]
Returns:Painter path for displaying the symbol

See also

setPath()

QwtSymbol.setPixmap(pixmap)[source]

Set a pixmap as symbol

Parameters:pixmap (QPixmap) – Pixmap

Note

The style() is set to QwtSymbol.Pixmap

Note

brush() and pen() have no effect

QwtSymbol.pixmap()[source]
Returns:Assigned pixmap

See also

setPixmap()

QwtSymbol.setGraphic(graphic)[source]

Set a graphic as symbol

Parameters:graphic (qwt.graphic.QwtGraphic) – Graphic

Note

The style() is set to QwtSymbol.Graphic

Note

brush() and pen() have no effect

QwtSymbol.graphic()[source]
Returns:Assigned graphic

See also

setGraphic()

QwtSymbol.setSvgDocument(svgDocument)[source]

Set a SVG icon as symbol

Parameters:svgDocument – SVG icon

Note

The style() is set to QwtSymbol.SvgDocument

Note

brush() and pen() have no effect

QwtSymbol.setSize(*args)[source]

Specify the symbol’s size

setSize(width[, height=-1])[source]
Parameters:
  • width (int) – Width
  • height (int) – Height
setSize(size)[source]
Parameters:size (QSize) – Size

See also

size()

QwtSymbol.size()[source]
Returns:Size

See also

setSize()

QwtSymbol.setBrush(brush)[source]

Assign a brush

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

Parameters:brush (QBrush) – Brush

See also

brush()

QwtSymbol.brush()[source]
Returns:Brush

See also

setBrush()

QwtSymbol.setPen(*args)[source]

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

setPen(color, width, style)[source]

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)[source]

Assign a pen

Parameters:pen (QPen) – New pen

See also

pen(), brush()

QwtSymbol.pen()[source]
Returns:Pen

See also

setPen(), brush()

QwtSymbol.setColor(color)[source]

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
QwtSymbol.setPinPoint(pos, enable=True)[source]

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
QwtSymbol.pinPoint()[source]
Returns:Pin point
QwtSymbol.setPinPointEnabled(on)[source]

En/Disable the pin point alignment

Parameters:on (bool) – Enabled, when on is true
QwtSymbol.isPinPointEnabled()[source]
Returns:True, when the pin point translation is enabled
QwtSymbol.drawSymbols(painter, points, numPoints=None)[source]

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
QwtSymbol.drawSymbol(painter, point_or_rect)[source]

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
QwtSymbol.renderSymbols(painter, points, numPoints=None)[source]

Render the symbol to series of points

Parameters:
  • painter (QPainter) – Painter
  • point_or_rect – Positions of the symbols
QwtSymbol.boundingRect()[source]

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

Returns:Bounding rectangle
QwtSymbol.invalidateCache()[source]

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.

QwtSymbol.setStyle(style)[source]

Specify the symbol style

Parameters:style (int) – Style

See also

style()

QwtSymbol.style()[source]
Returns:Current symbol style

See also

setStyle()