Scales — PythonQwt 0.14 Manual (original) (raw)
QwtScaleMap¶
class qwt.scale_map.QwtScaleMap(*args)[source]¶
A scale map
QwtScaleMap offers transformations from the coordinate system of a scale into the linear coordinate system of a paint device and vice versa.
The scale and paint device intervals are both set to [0,1].
class QwtScaleMap([_other=None_])¶
Constructor (eventually, copy constructor)
Parameters:
other (qwt.scale_map.QwtScaleMap) – Other scale map
class QwtScaleMap(p1, p2, s1, s2)
Constructor (was provided by PyQwt but not by Qwt)
Parameters:
- p1 (int) – First border of the paint interval
- p2 (int) – Second border of the paint interval
- s1 (float) – First border of the scale interval
- s2 (float) – Second border of the scale interval
Returns:
First border of the scale interval
Returns:
Second border of the scale interval
Returns:
First border of the paint interval
Returns:
Second border of the paint interval
Returns:
abs(p2() - p1())
Returns:
abs(s2() - s1())
Transform a point related to the scale interval into an point related to the interval of the paint device
Parameters:
s (float) – Value relative to the coordinates of the scale
Returns:
Transformed value
invTransform_scalar(p)[source]¶
Transform an paint device value into a value in the interval of the scale.
Parameters:
p (float) – Value relative to the coordinates of the paint device
Returns:
Transformed value
See also
Returns:
True, when ( p1() < p2() ) != ( s1() < s2() )
setTransformation(transform)[source]¶
Initialize the map with a transformation
Parameters:
transform (qwt.transform.QwtTransform) – Transformation
Returns:
the transformation
setScaleInterval(s1, s2)[source]¶
Specify the borders of the scale interval
Parameters:
- s1 (float) – first border
- s2 (float) – second border
Warning
Scales might be aligned to transformation depending boundaries
setPaintInterval(p1, p2)[source]¶
Specify the borders of the paint device interval
Parameters:
- p1 (float) – first border
- p2 (float) – second border
Transform a rectangle from scale to paint coordinates.
Transfom a scalar:
Parameters:
scalar (float) – Scalar
Transfom a rectangle:
Parameters:
- xMap (qwt.scale_map.QwtScaleMap) – X map
- yMap (qwt.scale_map.QwtScaleMap) – Y map
- rect (QRectF) – Rectangle in paint coordinates
Transfom a point:
Parameters:
- xMap (qwt.scale_map.QwtScaleMap) – X map
- yMap (qwt.scale_map.QwtScaleMap) – Y map
- pos (QPointF) – Position in scale coordinates
Transform from paint to scale coordinates
Scalar: scalemap.invTransform(scalar) Point (QPointF): scalemap.invTransform(xMap, yMap, pos) Rectangle (QRectF): scalemap.invTransform(xMap, yMap, rect)
QwtScaleWidget¶
class qwt.scale_widget.QwtScaleWidget(*args)[source]¶
A Widget which contains a scale
This Widget can be used to decorate composite widgets with a scale.
Layout flags:
- QwtScaleWidget.TitleInverted: The title of vertical scales is painted from top to bottom. Otherwise it is painted from bottom to top.
class QwtScaleWidget([_parent=None_])¶
Alignment default is QwtScaleDraw.LeftScale.
Parameters:
parent (QWidget or None) – Parent widget
class QwtScaleWidget(align, parent)
Parameters:
- align (int) – Alignment
- parent (QWidget) – Parent widget
Initialize the scale
Parameters:
align (int) – Alignment
setLayoutFlag(flag, on=True)[source]¶
Toggle an layout flag
Parameters:
- flag (int) – Layout flag
- on (bool) – True/False
See also
Test a layout flag
Parameters:
flag (int) – Layout flag
Returns:
True/False
Give title new text contents
Parameters:
title (qwt.text.QwtText or str) – New title
setAlignment(alignment)[source]¶
Change the alignment
Parameters:
alignment (int) – New alignment
Valid alignment values: see qwt.scale_draw.QwtScaleDraw
Returns:
position
setBorderDist(dist1, dist2)[source]¶
Specify distances of the scale’s endpoints from the widget’s borders. The actual borders will never be less than minimum border distance.
Parameters:
- dist1 (int) – Left or top Distance
- dist2 (int) – Right or bottom distance
Specify the margin to the colorBar/base line.
Parameters:
margin (int) – Margin
Specify the distance between color bar, scale and title
Parameters:
spacing (int) – Spacing
setLabelAlignment(alignment)[source]¶
Change the alignment for the labels.
Parameters:
spacing (int) – Spacing
setLabelRotation(rotation)[source]¶
Change the rotation for the labels.
Parameters:
rotation (float) – Rotation
See also
qwt.scale_draw.QwtScaleDraw.setLabelRotation(),setLabelFlags()
setLabelAutoSize(state)[source]¶
Set the automatic size option for labels (default: on).
Parameters:
state (bool) – On/off
setScaleDraw(scaleDraw)[source]¶
Set a scale draw
scaleDraw has to be created with new and will be deleted in class destructor or the next call of setScaleDraw(). scaleDraw will be initialized with the attributes of the previous scaleDraw object.
Parameters:
scaleDraw (qwt.scale_draw.QwtScaleDraw) – ScaleDraw object
Returns:
scaleDraw of this scale
See also
qwt.scale_draw.QwtScaleDraw.setScaleDraw()
Returns:
title
Returns:
start border distance
Returns:
end border distance
Returns:
margin
Returns:
distance between scale and title
paintEvent(self, a0: QPaintEvent | None)[source]¶
Draw the scale
Parameters:
painter (QPainter) – Painter
Calculate the the rectangle for the color bar
Parameters:
rect (QRectF) – Bounding rectangle for all components of the scale
Returns:
Rectangle for the color bar
resizeEvent(self, a0: QResizeEvent | None)[source]¶
layoutScale(update_geometry=True)[source]¶
Recalculate the scale’s geometry and layout based on the current geometry and fonts.
Parameters:
update_geometry (bool) – Notify the layout system and call update to redraw the scale
drawColorBar(painter, rect)[source]¶
Draw the color bar of the scale widget
Parameters:
- painter (QPainter) – Painter
- rect (QRectF) – Bounding rectangle for the color bar
drawTitle(painter, align, rect)[source]¶
Rotate and paint a title according to its position into a given rectangle.
Parameters:
- painter (QPainter) – Painter
- align (int) – Alignment
- rect (QRectF) – Bounding rectangle
Notify a change of the scale
This method can be overloaded by derived classes. The default implementation updates the geometry and repaints the widget.
sizeHint(self) → QSize[source]¶
minimumSizeHint(self) → QSize[source]¶
titleHeightForWidth(width)[source]¶
Find the height of the title for a given width.
Parameters:
width (int) – Width
Returns:
Height
dimForLength(length, scaleFont)[source]¶
Find the minimum dimension for a given length. dim is the height, length the width seen in direction of the title.
Parameters:
- length (int) – width for horizontal, height for vertical scales
- scaleFont (QFont) – Font of the scale
Returns:
height for horizontal, width for vertical scales
Calculate a hint for the border distances.
This member function calculates the distance of the scale’s endpoints from the widget borders which is required for the mark labels to fit into the widget. The maximum of this distance an the minimum border distance is returned.
Parameters:
- start (int) – Return parameter for the border width at the beginning of the scale
- end (int) – Return parameter for the border width at the end of the scale
Warning
The minimum border distance depends on the font.
setMinBorderDist(start, end)[source]¶
Set a minimum value for the distances of the scale’s endpoints from the widget borders. This is useful to avoid that the scales are “jumping”, when the tick labels or their positions change often.
Parameters:
- start (int) – Minimum for the start border
- end (int) – Minimum for the end border
Get the minimum value for the distances of the scale’s endpoints from the widget borders.
Parameters:
- start (int) – Return parameter for the border width at the beginning of the scale
- end (int) – Return parameter for the border width at the end of the scale
setScaleDiv(scaleDiv)[source]¶
Assign a scale division
The scale division determines where to set the tick marks.
Parameters:
scaleDiv (qwt.scale_div.QwtScaleDiv) – Scale Division
See also
For more information about scale divisions, see qwt.scale_div.QwtScaleDiv.
setTransformation(transformation)[source]¶
Set the transformation
Parameters:
transformation (qwt.transform.Transform) – Transformation
See also
qwt.scale_draw.QwtAbstractScaleDraw.scaleDraw()
,qwt.scale_map.QwtScaleMap
setColorBarEnabled(on)[source]¶
En/disable a color bar associated to the scale
Parameters:
on (bool) – On/Off
Returns:
True, when the color bar is enabled
setColorBarWidth(width)[source]¶
Set the width of the color bar
Parameters:
width (int) – Width
Returns:
Width of the color bar
Returns:
Value interval for the color bar
setColorMap(interval, colorMap)[source]¶
Set the color map and value interval, that are used for displaying the color bar.
Parameters:
- interval (qwt.interval.QwtInterval) – Value interval
- colorMap (qwt.color_map.QwtColorMap) – Color map
Returns:
Color map
QwtScaleDiv¶
class qwt.scale_div.QwtScaleDiv(*args)[source]¶
A class representing a scale division
A Qwt scale is defined by its boundaries and 3 list for the positions of the major, medium and minor ticks.
The upperLimit() might be smaller than the lowerLimit()to indicate inverted scales.
Scale divisions can be calculated from a QwtScaleEngine.
Scale tick types:
- QwtScaleDiv.NoTick: No ticks
- QwtScaleDiv.MinorTick: Minor ticks
- QwtScaleDiv.MediumTick: Medium ticks
- QwtScaleDiv.MajorTick: Major ticks
- QwtScaleDiv.NTickTypes: Number of valid tick types
class QwtScaleDiv¶
Basic constructor. Lower bound = Upper bound = 0.
class QwtScaleDiv(interval, ticks)
Parameters:
- interval (qwt.interval.QwtInterval) – Interval
- ticks (list) – list of major, medium and minor ticks
class QwtScaleDiv(lowerBound, upperBound)
Parameters:
- lowerBound (float) – First boundary
- upperBound (float) – Second boundary
class QwtScaleDiv(lowerBound, upperBound, ticks)
Parameters:
- lowerBound (float) – First boundary
- upperBound (float) – Second boundary
- ticks (list) – list of major, medium and minor ticks
class QwtScaleDiv(lowerBound, upperBound, minorTicks, mediumTicks, majorTicks)
Parameters:
- lowerBound (float) – First boundary
- upperBound (float) – Second boundary
- minorTicks (list) – list of minor ticks
- mediumTicks (list) – list of medium ticks
- majorTicks (list) – list of major ticks
Note
lowerBound might be greater than upperBound for inverted scales
Change the interval
setInterval(lowerBound, upperBound)[source]
Parameters:
- lowerBound (float) – First boundary
- upperBound (float) – Second boundary
setInterval(interval)[source]
Parameters:
interval (qwt.interval.QwtInterval) – Interval
Note
lowerBound might be greater than upperBound for inverted scales
Returns:
Interval
setLowerBound(lowerBound)[source]¶
Set the first boundary
Parameters:
lowerBound (float) – First boundary
Returns:
the first boundary
setUpperBound(upperBound)[source]¶
Set the second boundary
Parameters:
lowerBound (float) – Second boundary
Returns:
the second boundary
Returns:
upperBound() - lowerBound()
Check if the scale division is empty( lowerBound() == upperBound() )
Check if the scale division is increasing( lowerBound() <= upperBound() )
Return if a value is between lowerBound() and upperBound()
Parameters:
value (float) – Value
Returns:
True/False
Invert the scale division
Returns:
A scale division with inverted boundaries and ticks
bounded(lowerBound, upperBound)[source]¶
Return a scale division with an interval [lowerBound, upperBound] where all ticks outside this interval are removed
Parameters:
- lowerBound (float) – First boundary
- lowerBound – Second boundary
Returns:
Scale division with all ticks inside of the given interval
Note
lowerBound might be greater than upperBound for inverted scales
setTicks(tickType, ticks)[source]¶
Assign ticks
Parameters:
- type (int) – MinorTick, MediumTick or MajorTick
- ticks (list) – Values of the tick positions
Return a list of ticks
Parameters:
type (int) – MinorTick, MediumTick or MajorTick
Returns:
Tick list
QwtScaleEngine¶
class qwt.scale_engine.QwtScaleEngine(base=10)[source]¶
Base class for scale engines.
A scale engine tries to find “reasonable” ranges and step sizes for scales.
The layout of the scale can be varied with setAttribute().
PythonQwt offers implementations for logarithmic and linear scales.
Layout attributes:
- QwtScaleEngine.NoAttribute: No attributes
- QwtScaleEngine.IncludeReference: Build a scale which includes thereference() value
- QwtScaleEngine.Symmetric: Build a scale which is symmetric to thereference() value
- QwtScaleEngine.Floating: The endpoints of the scale are supposed to be equal the outmost included values plus the specified margins (seesetMargins()). If this attribute is not set, the endpoints of the scale will be integer multiples of the step size.
- QwtScaleEngine.Inverted: Turn the scale upside down
autoScale(maxNumSteps, x1, x2, stepSize, relativeMargin=0.0)[source]¶
Align and divide an interval
Parameters:
- maxNumSteps (int) – Max. number of steps
- x1 (float) – First limit of the interval (In/Out)
- x2 (float) – Second limit of the interval (In/Out)
- stepSize (float) – Step size
- relativeMargin (float) – Margin as a fraction of the interval width
Returns:
tuple (x1, x2, stepSize)
divideScale(x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.0)[source]¶
Calculate a scale division
Parameters:
- x1 (float) – First interval limit
- x2 (float) – Second interval limit
- maxMajorSteps (int) – Maximum for the number of major steps
- maxMinorSteps (int) – Maximum number of minor steps
- stepSize (float) – Step size. If stepSize == 0.0, the scaleEngine calculates one
Returns:
Calculated scale division
setTransformation(transform)[source]¶
Assign a transformation
Parameters:
transform (qwt.transform.QwtTransform) – Transformation
The transformation object is used as factory for clones that are returned by transformation()
The scale engine takes ownership of the transformation.
See also
QwtTransform.copy()
, transformation()
Create and return a clone of the transformation of the engine. When the engine has no special transformation None is returned, indicating no transformation.
Returns:
A clone of the transfomation
Returns:
the margin at the lower end of the scale
The default margin is 0.
Returns:
the margin at the upper end of the scale
The default margin is 0.
setMargins(lower, upper)[source]¶
Specify margins at the scale’s endpoints
Parameters:
- lower (float) – minimum distance between the scale’s lower boundary and the smallest enclosed value
- upper (float) – minimum distance between the scale’s upper boundary and the greatest enclosed value
Returns:
A clone of the transfomation
Margins can be used to leave a minimum amount of space between the enclosed intervals and the boundaries of the scale.
Warning
QwtLogScaleEngine measures the margins in decades.
divideInterval(intervalSize, numSteps)[source]¶
Calculate a step size for a given interval
Parameters:
- intervalSize (float) – Interval size
- numSteps (float) – Number of steps
Returns:
Step size
contains(interval, value)[source]¶
Check if an interval “contains” a value
Parameters:
- intervalSize (float) – Interval size
- value (float) – Value
Returns:
True, when the value is inside the interval
strip(ticks, interval)[source]¶
Remove ticks from a list, that are not inside an interval
Parameters:
- ticks (list) – Tick list
- interval (qwt.interval.QwtInterval) – Interval
Returns:
Stripped tick list
Build an interval around a value
In case of v == 0.0 the interval is [-0.5, 0.5], otherwide it is [0.5 * v, 1.5 * v]
Parameters:
value (float) – Initial value
Returns:
Calculated interval
setAttribute(attribute, on=True)[source]¶
Change a scale attribute
Parameters:
- attribute (int) – Attribute to change
- on (bool) – On/Off
Returns:
Calculated interval
testAttribute(attribute)[source]¶
Parameters:
attribute (int) – Attribute to be tested
Returns:
True, if attribute is enabled
setAttributes(attributes)[source]¶
Change the scale attribute
Parameters:
attributes – Set scale attributes
Returns:
Scale attributes
Specify a reference point
Parameters:
r (float) – new reference value
The reference point is needed if options IncludeReference orSymmetric are active. Its default value is 0.0.
Returns:
the reference value
Set the base of the scale engine
While a base of 10 is what 99.9% of all applications need certain scales might need a different base: f.e 2
The default setting is 10
Parameters:
base (int) – Base of the engine
Returns:
Base of the scale engine
QwtLinearScaleEngine¶
class qwt.scale_engine.QwtLinearScaleEngine(base=10)[source]¶
A scale engine for linear scales
The step size will fit into the pattern f$left{ 1,2,5right} cdot 10^{n}f$, where n is an integer.
autoScale(maxNumSteps, x1, x2, stepSize, relativeMargin=0.0)[source]¶
Align and divide an interval
Parameters:
- maxNumSteps (int) – Max. number of steps
- x1 (float) – First limit of the interval (In/Out)
- x2 (float) – Second limit of the interval (In/Out)
- stepSize (float) – Step size
- relativeMargin (float) – Margin as a fraction of the interval width
Returns:
tuple (x1, x2, stepSize)
divideScale(x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.0)[source]¶
Calculate a scale division for an interval
Parameters:
- x1 (float) – First interval limit
- x2 (float) – Second interval limit
- maxMajorSteps (int) – Maximum for the number of major steps
- maxMinorSteps (int) – Maximum number of minor steps
- stepSize (float) – Step size. If stepSize == 0.0, the scaleEngine calculates one
Returns:
Calculated scale division
buildTicks(interval, stepSize, maxMinorSteps)[source]¶
Calculate ticks for an interval
Parameters:
- interval (qwt.interval.QwtInterval) – Interval
- stepSize (float) – Step size
- maxMinorSteps (int) – Maximum number of minor steps
Returns:
Calculated ticks
buildMajorTicks(interval, stepSize)[source]¶
Calculate major ticks for an interval
Parameters:
- interval (qwt.interval.QwtInterval) – Interval
- stepSize (float) – Step size
Returns:
Calculated ticks
buildMinorTicks(ticks, maxMinorSteps, stepSize)[source]¶
Calculate minor ticks for an interval
Parameters:
- ticks (list) – Major ticks (returned)
- maxMinorSteps (int) – Maximum number of minor steps
- stepSize (float) – Step size
align(interval, stepSize)[source]¶
Align an interval to a step size
The limits of an interval are aligned that both are integer multiples of the step size.
Parameters:
- interval (qwt.interval.QwtInterval) – Interval
- stepSize (float) – Step size
Returns:
Aligned interval
QwtLogScaleEngine¶
class qwt.scale_engine.QwtLogScaleEngine(base=10)[source]¶
A scale engine for logarithmic scales
The step size is measured in decades and the major step size will be adjusted to fit the pattern {1,2,3,5}.10**n, where n is a natural number including zero.
Warning
The step size as well as the margins are measured in decades.
autoScale(maxNumSteps, x1, x2, stepSize, relativeMargin=0.0)[source]¶
Align and divide an interval
Parameters:
- maxNumSteps (int) – Max. number of steps
- x1 (float) – First limit of the interval (In/Out)
- x2 (float) – Second limit of the interval (In/Out)
- stepSize (float) – Step size
- relativeMargin (float) – Margin as a fraction of the interval width
Returns:
tuple (x1, x2, stepSize)
divideScale(x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.0)[source]¶
Calculate a scale division for an interval
Parameters:
- x1 (float) – First interval limit
- x2 (float) – Second interval limit
- maxMajorSteps (int) – Maximum for the number of major steps
- maxMinorSteps (int) – Maximum number of minor steps
- stepSize (float) – Step size. If stepSize == 0.0, the scaleEngine calculates one
Returns:
Calculated scale division
buildTicks(interval, stepSize, maxMinorSteps)[source]¶
Calculate ticks for an interval
Parameters:
- interval (qwt.interval.QwtInterval) – Interval
- stepSize (float) – Step size
- maxMinorSteps (int) – Maximum number of minor steps
Returns:
Calculated ticks
buildMajorTicks(interval, stepSize)[source]¶
Calculate major ticks for an interval
Parameters:
- interval (qwt.interval.QwtInterval) – Interval
- stepSize (float) – Step size
Returns:
Calculated ticks
buildMinorTicks(ticks, maxMinorSteps, stepSize)[source]¶
Calculate minor ticks for an interval
Parameters:
- ticks (list) – Major ticks (returned)
- maxMinorSteps (int) – Maximum number of minor steps
- stepSize (float) – Step size
align(interval, stepSize)[source]¶
Align an interval to a step size
The limits of an interval are aligned that both are integer multiples of the step size.
Parameters:
- interval (qwt.interval.QwtInterval) – Interval
- stepSize (float) – Step size
Returns:
Aligned interval
QwtAbstractScaleDraw¶
class qwt.scale_draw.QwtAbstractScaleDraw[source]¶
A abstract base class for drawing scales
QwtAbstractScaleDraw can be used to draw linear or logarithmic scales.
After a scale division has been specified as a QwtScaleDiv object using setScaleDiv(), the scale can be drawn with the draw() member.
Scale components:
- QwtAbstractScaleDraw.Backbone: Backbone = the line where the ticks are located
- QwtAbstractScaleDraw.Ticks: Ticks
- QwtAbstractScaleDraw.Labels: Labels
class QwtAbstractScaleDraw¶
The range of the scale is initialized to [0, 100], The spacing (distance between ticks and labels) is set to 4, the tick lengths are set to 4,6 and 8 pixels
Calculate the extent
The extent is the distance from the baseline to the outermost pixel of the scale draw in opposite to its orientation. It is at least minimumExtent() pixels.
Parameters:
font (QFont) – Font used for drawing the tick labels
Returns:
Number of pixels
drawTick(painter, value, len_)[source]¶
Draw a tick
Parameters:
- painter (QPainter) – Painter
- value (float) – Value of the tick
- len (float) – Length of the tick
drawBackbone(painter)[source]¶
Draws the baseline of the scale
Parameters:
painter (QPainter) – Painter
See also
drawLabel(painter, value)[source]¶
Draws the label for a major scale tick
Parameters:
- painter (QPainter) – Painter
- value (float) – Value
enableComponent(component, enable)[source]¶
En/Disable a component of the scale
Parameters:
- component (int) – Scale component
- enable (bool) – On/Off
hasComponent(component)[source]¶
Check if a component is enabled
Parameters:
component (int) – Component type
Returns:
True, when component is enabled
See also
setScaleDiv(scaleDiv)[source]¶
Change the scale division
Parameters:
scaleDiv (qwt.scale_div.QwtScaleDiv) – New scale division
setTransformation(transformation)[source]¶
Change the transformation of the scale
Parameters:
transformation (qwt.transform.QwtTransform) – New scale transformation
Returns:
Map how to translate between scale and pixel values
Returns:
scale division
Specify the width of the scale pen
Parameters:
width (int) – Pen width
Returns:
Scale pen width
draw(painter, palette)[source]¶
Draw the scale
Parameters:
- painter (QPainter) – The painter
- palette (QPalette) – Palette, text color is used for the labels, foreground color for ticks and backbone
Set the spacing between tick and labels
The spacing is the distance between ticks and labels. The default spacing is 4 pixels.
Parameters:
spacing (float) – Spacing
Get the spacing
The spacing is the distance between ticks and labels. The default spacing is 4 pixels.
Returns:
Spacing
setMinimumExtent(minExtent)[source]¶
Set a minimum for the extent
The extent is calculated from the components of the scale draw. In situations, where the labels are changing and the layout depends on the extent (f.e scrolling a scale), setting an upper limit as minimum extent will avoid jumps of the layout.
Parameters:
minExtent (float) – Minimum extent
Get the minimum extent
Returns:
Minimum extent
setTickLength(tick_type, length)[source]¶
Set the length of the ticks
Parameters:
- tick_type (int) – Tick type
- length (float) – New length
Warning
the length is limited to [0..1000]
tickLength(tick_type)[source]¶
Parameters:
tick_type (int) – Tick type
Returns:
Length of the ticks
Returns:
Length of the longest tick
Useful for layout calculations
setTickLighterFactor(tick_type, factor)[source]¶
Set the color lighter factor of the ticks
Parameters:
- tick_type (int) – Tick type
- factor (int) – New factor
tickLighterFactor(tick_type)[source]¶
Parameters:
tick_type (int) – Tick type
Returns:
Color lighter factor of the ticks
Convert a value into its representing label
The value is converted to a plain text usingQLocale().toString(value). This method is often overloaded by applications to have individual labels.
Parameters:
value (float) – Value
Returns:
Label string
tickLabel(font, value)[source]¶
Convert a value into its representing label and cache it.
The conversion between value and label is called very often in the layout and painting code. Unfortunately the calculation of the label sizes might be slow (really slow for rich text in Qt4), so it’s necessary to cache the labels.
Parameters:
- font (QFont) – Font
- value (float) – Value
Returns:
Tuple (tick label, text size)
Invalidate the cache used by tickLabel()
The cache is invalidated, when a new QwtScaleDiv is set. If the labels need to be changed. while the same QwtScaleDiv is set,invalidateCache() needs to be called manually.
QwtScaleDraw¶
class qwt.scale_draw.QwtScaleDraw[source]¶
A class for drawing scales
QwtScaleDraw can be used to draw linear or logarithmic scales. A scale has a position, an alignment and a length, which can be specified . The labels can be rotated and aligned to the ticks using setLabelRotation() and setLabelAlignment().
After a scale division has been specified as a QwtScaleDiv object using QwtAbstractScaleDraw.setScaleDiv(scaleDiv), the scale can be drawn with the QwtAbstractScaleDraw.draw() member.
Alignment of the scale draw:
- QwtScaleDraw.BottomScale: The scale is below
- QwtScaleDraw.TopScale: The scale is above
- QwtScaleDraw.LeftScale: The scale is left
- QwtScaleDraw.RightScale: The scale is right
class QwtScaleDraw¶
The range of the scale is initialized to [0, 100], The position is at (0, 0) with a length of 100. The orientation is QwtAbstractScaleDraw.Bottom.
Returns:
Alignment of the scale
Set the alignment of the scale
Parameters:
align (int) – Alignment of the scale
Alignment of the scale draw:
- QwtScaleDraw.BottomScale: The scale is below
- QwtScaleDraw.TopScale: The scale is above
- QwtScaleDraw.LeftScale: The scale is left
- QwtScaleDraw.RightScale: The scale is right
The default alignment is QwtScaleDraw.BottomScale
Return the orientation
TopScale, BottomScale are horizontal (Qt.Horizontal) scales, LeftScale, RightScale are vertical (Qt.Vertical) scales.
Returns:
Orientation of the scale
getBorderDistHint(font)[source]¶
Determine the minimum border distance
This member function returns the minimum space needed to draw the mark labels at the scale’s endpoints.
Parameters:
font (QFont) – Font
Returns:
tuple (start, end)
Returned tuple:
- start: Start border distance
- end: End border distance
Determine the minimum distance between two labels, that is necessary that the texts don’t overlap.
Parameters:
font (QFont) – Font
Returns:
The maximum width of a label
Calculate the width/height that is needed for a vertical/horizontal scale.
The extent is calculated from the pen width of the backbone, the major tick length, the spacing and the maximum width/height of the labels.
Parameters:
font (QFont) – Font used for painting the labels
Returns:
Extent
Calculate the minimum length that is needed to draw the scale
Parameters:
font (QFont) – Font used for painting the labels
Returns:
Minimum length that is needed to draw the scale
Find the position, where to paint a label
The position has a distance that depends on the length of the ticks in direction of the alignment().
Parameters:
value (float) – Value
Returns:
Position, where to paint a label
drawTick(painter, value, len_)[source]¶
Draw a tick
Parameters:
- painter (QPainter) – Painter
- value (float) – Value of the tick
- len (float) – Length of the tick
drawBackbone(painter)[source]¶
Draws the baseline of the scale
Parameters:
painter (QPainter) – Painter
See also
Move the position of the scale
The meaning of the parameter pos depends on the alignment:
- QwtScaleDraw.LeftScale:
The origin is the topmost point of the backbone. The backbone is a vertical line. Scale marks and labels are drawn at the left of the backbone.- QwtScaleDraw.RightScale:
The origin is the topmost point of the backbone. The backbone is a vertical line. Scale marks and labels are drawn at the right of the backbone.- QwtScaleDraw.TopScale:
The origin is the leftmost point of the backbone. The backbone is a horizontal line. Scale marks and labels are drawn above the backbone.- QwtScaleDraw.BottomScale:
The origin is the leftmost point of the backbone. The backbone is a horizontal line Scale marks and labels are drawn below the backbone.
move(x, y)[source]
Parameters:
- x (float) – X coordinate
- y (float) – Y coordinate
move(pos)[source]
Parameters:
pos (QPointF) – position
See also
Returns:
Origin of the scale
See also
Set the length of the backbone.
The length doesn’t include the space needed for overlapping labels.
Parameters:
length (float) – Length of the backbone
See also
Returns:
the length of the backbone
See also
drawLabel(painter, value)[source]¶
Draws the label for a major scale tick
Parameters:
- painter (QPainter) – Painter
- value (float) – Value
boundingLabelRect(font, value)[source]¶
Find the bounding rectangle for the label.
The coordinates of the rectangle are absolute (calculated frompos()) in direction of the tick.
Parameters:
- font (QFont) – Font used for painting
- value (float) – Value
Returns:
Bounding rectangle
labelTransformation(pos, size)[source]¶
Calculate the transformation that is needed to paint a label depending on its alignment and rotation.
Parameters:
- pos (QPointF) – Position where to paint the label
- size (QSizeF) – Size of the label
Returns:
Transformation matrix
labelRect(font, value)[source]¶
Find the bounding rectangle for the label. The coordinates of the rectangle are relative to spacing + tick length from the backbone in direction of the tick.
Parameters:
- font (QFont) – Font used for painting
- value (float) – Value
Returns:
Bounding rectangle that is needed to draw a label
labelSize(font, value)[source]¶
Calculate the size that is needed to draw a label
Parameters:
- font (QFont) – Label font
- value (float) – Value
Returns:
Size that is needed to draw a label
setLabelRotation(rotation)[source]¶
Rotate all labels.
When changing the rotation, it might be necessary to adjust the label flags too. Finding a useful combination is often the result of try and error.
Parameters:
rotation (float) – Angle in degrees. When changing the label rotation, the label flags often needs to be adjusted too.
Returns:
the label rotation
setLabelAlignment(alignment)[source]¶
Change the label flags
Labels are aligned to the point tick length + spacing away from the backbone.
The alignment is relative to the orientation of the label text. In case of an flags of 0 the label will be aligned depending on the orientation of the scale:
- QwtScaleDraw.TopScale: Qt.AlignHCenter | Qt.AlignTop
- QwtScaleDraw.BottomScale: Qt.AlignHCenter | Qt.AlignBottom
- QwtScaleDraw.LeftScale: Qt.AlignLeft | Qt.AlignVCenter
- QwtScaleDraw.RightScale: Qt.AlignRight | Qt.AlignVCenter
Changing the alignment is often necessary for rotated labels.
:param Qt.Alignment alignment Or’d Qt.AlignmentFlags
Warning
The various alignments might be confusing. The alignment of the label is not the alignment of the scale and is not the alignment of the flags (QwtText.flags()) returned fromQwtAbstractScaleDraw.label().
Returns:
the label flags
setLabelAutoSize(state)[source]¶
Set label automatic size option state
When drawing text labels, if automatic size mode is enabled (default behavior), the axes are drawn in order to optimize layout space and depends on text label individual sizes. Otherwise, width and height won’t change when axis range is changing.
This option is not implemented in Qwt C++ library: this may be used either as an optimization (updating plot layout is faster when this option is enabled) or as an appearance preference (with Qwt default behavior, the size of axes may change when zooming and/or panning plot canvas which in some cases may not be desired).
Parameters:
state (bool) – On/off
Returns:
True if automatic size option is enabled for labels
See also
Parameters:
font (QFont) – Font
Returns:
the maximum width of a label
Parameters:
font (QFont) – Font
Returns:
the maximum height of a label