QwtPlot Layout Management¶
QwtPlotLayout is the layout engine for QwtPlot, responsible for organizing the positions and sizes of internal components within the plot window, including the title, legend, axes, and canvas area.
Key Features¶
Features
- Automatic layout calculation: Automatically calculates reasonable space allocation based on component content
- Flexible spacing control: Supports custom canvas margins and component spacing
- Canvas alignment options: Choose to align the canvas with axis ticks or keep it independent
- Legend position configuration: Supports placing the legend at four boundary positions with configurable ratio
- Export optimization options: Can ignore scrollbars, frames, and other elements during export
Basic Concepts¶
Plot Window Structure¶
A QwtPlot window consists of the following components:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Getting Component Regions¶
QwtPlotLayout provides methods to retrieve the layout rectangles of each component:
| Method | Description |
|---|---|
titleRect() |
Get the title area rectangle |
footerRect() |
Get the footer area rectangle |
legendRect() |
Get the legend area rectangle |
scaleRect(QwtAxisId) |
Get the specified axis area rectangle |
canvasRect() |
Get the canvas area rectangle |
Usage¶
Setting Canvas Margins¶
Canvas margin is the whitespace between the canvas and the axes:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Margin Purpose
Canvas margins are primarily used to control the distance between axis tick labels and the canvas edge, preventing tick labels from being clipped.
Setting Component Spacing¶
Spacing controls the distance between the title, canvas, legend, and footer:
1 2 3 4 5 | |
Canvas and Axis Alignment¶
By default, canvas boundaries align with axis tick marks, ensuring ticks fall exactly at the canvas edge. You can also disable alignment to keep the canvas independent:
1 2 3 4 5 6 7 8 9 10 11 | |
Alignment Effect Description
- Aligned mode: Canvas boundaries precisely align with axis tick marks; tick labels may extend beyond the canvas
- Non-aligned mode: Canvas maintains a fixed size; axis areas are calculated independently; tick labels are fully displayed
Legend Position Configuration¶
QwtPlotLayout supports placing the legend at four boundary positions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Legend position options:
| Position | Enum Value | Description |
|---|---|---|
| Left | QwtPlot::LeftLegend |
Legend to the left of the YLeft axis |
| Right | QwtPlot::RightLegend |
Legend to the right of the YRight axis |
| Bottom | QwtPlot::BottomLegend |
Legend below the footer |
| Top | QwtPlot::TopLegend |
Legend above the title |
Layout Activation and Refresh¶
The layout needs to be recalculated when the QwtPlot size changes or component content changes:
1 2 3 4 5 | |
Export Layout Options¶
Special options can be used to ignore certain components when exporting a plot:
1 2 3 4 5 6 | |
| Option | Description |
|---|---|
AlignScales |
Align axes (unused) |
IgnoreScrollbars |
Ignore scrollbar dimensions |
IgnoreFrames |
Ignore all frame borders |
IgnoreLegend |
Ignore legend |
IgnoreTitle |
Ignore title |
IgnoreFooter |
Ignore footer |
Custom Layout Example¶
The following example demonstrates how to customize the plot layout:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
Layout Change Timing
After layout settings are changed, you need to call plot->replot() or wait for the next automatic refresh to see the effect.
Minimum Size Hints¶
QwtPlotLayout can calculate minimum dimensions based on component content:
1 2 3 4 5 | |
Related Examples
- Basic layout: All examples under
examples/2D/ - Multi-plot layout:
examples/figure(using QwtFigure)