base
Base class for plot widgets that provides common functionality like shaded curve drawing.
Classes
Context object holding plot state for drawing operations. |
|
Configuration for plot appearance. |
|
Base class for plot widgets that provides common shading functionality. |
Module Contents
- class base.PlotContext[source]
Context object holding plot state for drawing operations.
This eliminates the need to pass multiple parameters repeatedly and provides coordinate conversion helpers.
- Parameters:
painter – QPainter instance for drawing
left_pad – Left padding of the plot area in pixels
plot_w – Width of the plot area in pixels
plot_h – Height of the plot area in pixels
top_pad – Top padding of the plot area in pixels
y_max – Maximum Y value in data coordinates
y_min – Minimum Y value in data coordinates
zero_y – Y coordinate of the zero line in pixels (optional, calculated if not provided)
- class base.PlotConfig[source]
Configuration for plot appearance.
Centralizes colors, fonts, padding, and other visual settings.
- class base.BasePlotWidget[source]
Bases:
PySide6.QtWidgets.QWidgetBase class for plot widgets that provides common shading functionality.
- draw_background(painter: PySide6.QtGui.QPainter) None[source]
Draw the background gradient for the plot.
- Parameters:
painter – QPainter instance
- set_dimensions(height: int, width: int)[source]
Set address fixed size for the widget (or use layouts as needed)
- draw_shaded_curve(painter: PySide6.QtGui.QPainter, path: PySide6.QtGui.QPainterPath, top_pad: int, plot_h: int, zero_y: float, left_pad: int, plot_w: int) None[source]
Draw a shaded fill under the curve with a gradient.
- Parameters:
painter – QPainter instance
path – QPainterPath representing the curve (may or may not be closed)
top_pad – Top padding of the plot area
plot_h – Height of the plot area
zero_y – Y coordinate of the zero line
left_pad – Left padding of the plot area
plot_w – Width of the plot area
- draw_grid(painter: PySide6.QtGui.QPainter, top_pad: int, plot_h: int, left_pad: int, plot_w: int, num_vertical_lines: int = 6, num_horizontal_lines: int = 5, y_min: float = 0.0, y_max: float = 1.0, y_callback: Callable[[float], float] | None = None) None[source]
Draw grid lines matching FilterPlot style.
- Parameters:
painter – QPainter instance
top_pad – Top padding of the plot area
plot_h – Height of the plot area
left_pad – Left padding of the plot area
plot_w – Width of the plot area
num_vertical_lines – Number of vertical grid lines (default: 6)
num_horizontal_lines – Number of horizontal grid lines (default: 5)
y_min – Minimum Y value for scaling (default: 0.0)
y_max – Maximum Y value for scaling (default: 1.0)
y_callback – Optional callback function(y_val) -> y_pixel for custom Y coordinate calculation
- draw_title(painter: PySide6.QtGui.QPainter, title: str, left_pad: int, plot_w: int, top_pad: int, config: PlotConfig | None = None) None[source]
Draw a centered title at the top of the plot.
This method matches the style of draw_title_ctx for consistency. Prefer using draw_title_ctx with PlotContext for new code.
- Parameters:
painter – QPainter instance
title – Title text to digital
left_pad – Left padding of the plot area
plot_w – Width of the plot area
top_pad – Top padding of the plot area
config – Optional PlotConfig (uses get_plot_config() if not provided)
- draw_x_axis_label(painter: PySide6.QtGui.QPainter, label: str, left_pad: int, plot_w: int, plot_h: int, top_pad: int, config: PlotConfig | None = None) None[source]
Draw a centered X-axis label at the bottom of the plot.
This method matches the style of draw_x_axis_label_ctx for consistency. Prefer using draw_x_axis_label_ctx with PlotContext for new code.
- Parameters:
painter – QPainter instance
label – Label text to digital
left_pad – Left padding of the plot area
plot_w – Width of the plot area
plot_h – Height of the plot area
top_pad – Top padding of the plot area
config – Optional PlotConfig (uses get_plot_config() if not provided)
- draw_y_axis_label(painter: PySide6.QtGui.QPainter, label: str, left_pad: int, plot_h: int, top_pad: int, config: PlotConfig | None = None) None[source]
Draw a rotated Y-axis label on the left side of the plot.
This method matches the style of draw_y_axis_label_ctx for consistency. Prefer using draw_y_axis_label_ctx with PlotContext for new code.
- Parameters:
painter – QPainter instance
label – Label text to digital
left_pad – Left padding of the plot area
plot_h – Height of the plot area
top_pad – Top padding of the plot area
config – Optional PlotConfig (uses get_plot_config() if not provided)
- set_pen(painter: PySide6.QtGui.QPainter) PySide6.QtGui.QPen[source]
Set up pens and fonts for plotting.
- Parameters:
painter – QPainter instance
- Returns:
QPen for drawing axes
- plot_dimensions(top_padding: int = 50, bottom_padding: int = 50, left_padding: int = 80, right_padding: int = 50) tuple[int, int, int, int][source]
Get plot area dimensions.
- Parameters:
top_padding – Top padding (default: 50)
bottom_padding – Bottom padding (default: 50)
left_padding – Left padding (default: 80)
right_padding – Right padding (default: 50)
- Returns:
Tuple of (left_pad, plot_h, plot_w, top_pad)
- create_plot_context(painter: PySide6.QtGui.QPainter, top_padding: int = 50, bottom_padding: int = 50, left_padding: int = 80, right_padding: int = 50, y_max: float = 1.0, y_min: float = 0.0) PlotContext[source]
Create a PlotContext from current widget dimensions and provided parameters.
This is a convenience method that combines plot_dimensions() with PlotContext creation.
- Parameters:
painter – QPainter instance for drawing
top_padding – Top padding (default: 50)
bottom_padding – Bottom padding (default: 50)
left_padding – Left padding (default: 80)
right_padding – Right padding (default: 50)
y_max – Maximum Y value in data coordinates (default: 1.0)
y_min – Minimum Y value in data coordinates (default: 0.0)
- Returns:
PlotContext instance
- calculate_zero_y(top_pad: int, plot_h: int, y_max: float, y_min: float, zero_at_bottom: bool = False) float[source]
Calculate the Y coordinate of the zero line.
- Parameters:
top_pad – Top padding of the plot area
plot_h – Height of the plot area
y_max – Maximum Y value
y_min – Minimum Y value
zero_at_bottom – If True, zero line is at bottom of plot (default: False, calculated from y_max/y_min)
- Returns:
Y coordinate of the zero line
- draw_axes(axis_pen: PySide6.QtGui.QPen, left_pad: int, painter: PySide6.QtGui.QPainter, plot_h: int, plot_w: int, top_pad: int, y_max: float, y_min: float, zero_at_bottom: bool = False) float[source]
Draw axes (Y-axis and X-axis at zero line).
- Parameters:
axis_pen – Pen for drawing axes
left_pad – Left padding of the plot area
painter – QPainter instance
plot_h – Height of the plot area
plot_w – Width of the plot area
top_pad – Top padding of the plot area
y_max – Maximum Y value
y_min – Minimum Y value
zero_at_bottom – If True, zero line is at bottom of plot (default: False)
- Returns:
Y coordinate of the zero line
- draw_title_ctx(ctx: PlotContext, title: str, config: PlotConfig | None = None) None[source]
Draw a centered title at the top of the plot using PlotContext.
- Parameters:
ctx – PlotContext containing plot state
title – Title text to digital
config – Optional PlotConfig (uses get_plot_config() if not provided)
- draw_x_axis_label_ctx(ctx: PlotContext, label: str, config: PlotConfig | None = None) None[source]
Draw a centered X-axis label at the bottom of the plot using PlotContext.
- Parameters:
ctx – PlotContext containing plot state
label – Label text to digital
config – Optional PlotConfig (uses get_plot_config() if not provided)
- draw_y_axis_label_ctx(ctx: PlotContext, label: str, config: PlotConfig | None = None) None[source]
Draw a rotated Y-axis label on the left side of the plot using PlotContext.
- Parameters:
ctx – PlotContext containing plot state
label – Label text to digital
config – Optional PlotConfig (uses get_plot_config() if not provided)
- draw_axes_ctx(ctx: PlotContext, zero_at_bottom: bool = False, config: PlotConfig | None = None) PlotContext[source]
Draw axes (Y-axis and X-axis at zero line) using PlotContext. Updates and returns the context with zero_y calculated.
- Parameters:
ctx – PlotContext containing plot state
zero_at_bottom – If True, zero line is at bottom of plot (default: False)
config – Optional PlotConfig (uses get_plot_config() if not provided)
- Returns:
Updated PlotContext with zero_y set
- draw_shaded_curve_ctx(ctx: PlotContext, path: PySide6.QtGui.QPainterPath) None[source]
Draw a shaded fill under the curve with a gradient using PlotContext.
- Parameters:
ctx – PlotContext containing plot state (must have zero_y set)
path – QPainterPath representing the curve (may or may not be closed)
- draw_x_axis_ticks(ctx: PlotContext, tick_values: list[float], tick_labels: list[str] | None = None, tick_length: int = 5, label_offset: int = 20, position: str = 'bottom', x_max: float | None = None, config: PlotConfig | None = None) None[source]
Draw X-axis tick marks and labels.
- Parameters:
ctx – PlotContext containing plot state
tick_values – List of X values (in data coordinates) for tick positions
tick_labels – Optional list of label strings (defaults to formatted tick_values)
tick_length – Length of tick marks in pixels (default: 5)
label_offset – Vertical offset for labels in pixels (default: 20)
position – Where to draw ticks - “bottom”, “top”, or “zero” for zero line (default: “bottom”)
x_max – Maximum X value for scaling (required if tick_values are in data coordinates)
config – Optional PlotConfig (uses get_plot_config() if not provided)
- draw_y_axis_ticks(ctx: PlotContext, tick_values: list[float], tick_labels: list[str] | None = None, tick_length: int = 5, label_offset: int = 45, zero_at_bottom: bool = False, config: PlotConfig | None = None) None[source]
Draw Y-axis tick marks and labels.
- Parameters:
ctx – PlotContext containing plot state
tick_values – List of Y values (in data coordinates) for tick positions
tick_labels – Optional list of label strings (defaults to formatted tick_values)
tick_length – Length of tick marks in pixels (default: 5)
label_offset – Horizontal offset for labels in pixels (default: 45)
zero_at_bottom – Whether zero is at bottom of plot (default: False)
config – Optional PlotConfig (uses get_plot_config() if not provided)
- draw_grid_ctx(ctx: PlotContext, x_ticks: list[float] | None = None, y_ticks: list[float] | None = None, x_max: float | None = None, num_vertical_lines: int | None = 6, num_horizontal_lines: int | None = 5, zero_at_bottom: bool = False, y_callback: Callable[[float], float] | None = None, config: PlotConfig | None = None) None[source]
Draw grid lines with optional custom tick positions using PlotContext.
- Parameters:
ctx – PlotContext containing plot state
x_ticks – Custom X tick positions (in data coordinates), overrides num_vertical_lines
y_ticks – Custom Y tick positions (in data coordinates), overrides num_horizontal_lines
x_max – Maximum X value for scaling (required if x_ticks provided)
num_vertical_lines – Number of vertical grid lines (if x_ticks not provided, default: 6)
num_horizontal_lines – Number of horizontal grid lines (if y_ticks not provided, default: 5)
zero_at_bottom – Whether zero is at bottom of plot (default: False)
y_callback – Optional callback function(y_val) -> y_pixel for custom Y coordinate calculation
config – Optional PlotConfig (uses get_plot_config() if not provided)
- value_to_x_pixel(ctx: PlotContext, value: float, x_max: float) float[source]
Convert X data value to pixel coordinate using PlotContext.
- Parameters:
ctx – PlotContext containing plot state
value – X value in data coordinates (0 to x_max)
x_max – Maximum X value in data coordinates
- Returns:
X coordinate in pixels
- value_to_y_pixel(ctx: PlotContext, value: float, zero_at_bottom: bool = False) float[source]
Convert Y data value to pixel coordinate using PlotContext.
- Parameters:
ctx – PlotContext containing plot state
value – Y value in data coordinates
zero_at_bottom – If True, zero is at bottom of plot (default: False)
- Returns:
Y coordinate in pixels
- get_plot_config() PlotConfig[source]
Get plot configuration. Override to customize appearance.
- Returns:
PlotConfig instance
- get_title_font(config: PlotConfig | None = None) PySide6.QtGui.QFont[source]
Get font for plot title.
- Parameters:
config – Optional PlotConfig (uses get_plot_config() if not provided)
- Returns:
QFont for title
- get_label_font(config: PlotConfig | None = None) PySide6.QtGui.QFont[source]
Get font for axis labels.
- Parameters:
config – Optional PlotConfig (uses get_plot_config() if not provided)
- Returns:
QFont for labels
- get_tick_font(config: PlotConfig | None = None) PySide6.QtGui.QFont[source]
Get font for tick labels.
- Parameters:
config – Optional PlotConfig (uses get_plot_config() if not provided)
- Returns:
QFont for ticks
- get_envelope_pen(config: PlotConfig | None = None) PySide6.QtGui.QPen[source]
Get pen for drawing envelope curves.
- Parameters:
config – Optional PlotConfig (uses get_plot_config() if not provided)
- Returns:
QPen for envelope
- get_axis_pen(config: PlotConfig | None = None) PySide6.QtGui.QPen[source]
Get pen for drawing axes.
- Parameters:
config – Optional PlotConfig (uses get_plot_config() if not provided)
- Returns:
QPen for axes
- get_grid_pen(config: PlotConfig | None = None) PySide6.QtGui.QPen[source]
Get pen for drawing grid lines.
- Parameters:
config – Optional PlotConfig (uses get_plot_config() if not provided)
- Returns:
QPen for grid
- get_point_pen(config: PlotConfig | None = None) PySide6.QtGui.QPen[source]
Get pen for drawing points.
- Parameters:
config – Optional PlotConfig (uses get_plot_config() if not provided)
- Returns:
QPen for points
- draw_curve_from_array(ctx: PlotContext, y_values: list[float] | numpy.ndarray, x_max: float, sample_rate: float = 1.0, max_points: int = 500, zero_at_bottom: bool = False, config: PlotConfig | None = None) PySide6.QtGui.QPainterPath[source]
Draw a curve from an array of Y values.
- Parameters:
ctx – PlotContext containing plot state
y_values – Array or list of Y values (in data coordinates)
x_max – Maximum X value (total time/duration in data coordinates)
sample_rate – Sample rate for converting indices to time (default: 1.0)
max_points – Maximum number of points to draw (default: 500)
zero_at_bottom – Whether zero is at bottom of plot (default: False)
config – Optional PlotConfig (uses get_plot_config() if not provided)
- Returns:
QPainterPath representing the curve
- draw_curve_from_points(ctx: PlotContext, points: list[tuple[float, float]], x_max: float, zero_at_bottom: bool = False, config: PlotConfig | None = None) PySide6.QtGui.QPainterPath[source]
Draw a curve from a list of (x, y) tuples in data coordinates.
- Parameters:
ctx – PlotContext containing plot state
points – List of (x, y) tuples in data coordinates
x_max – Maximum X value for scaling
zero_at_bottom – Whether zero is at bottom of plot (default: False)
config – Optional PlotConfig (uses get_plot_config() if not provided)
- Returns:
QPainterPath representing the curve
- draw_shaded_curve_from_array(ctx: PlotContext, y_values: list[float] | numpy.ndarray, x_max: float, sample_rate: float = 1.0, max_points: int = 500, zero_at_bottom: bool = False, config: PlotConfig | None = None) None[source]
Draw a curve with shaded fill from an array of Y values.
- Parameters:
ctx – PlotContext containing plot state (must have zero_y set)
y_values – Array or list of Y values (in data coordinates)
x_max – Maximum X value (total time/duration in data coordinates)
sample_rate – Sample rate for converting indices to time (default: 1.0)
max_points – Maximum number of points to draw (default: 500)
zero_at_bottom – Whether zero is at bottom of plot (default: False)
config – Optional PlotConfig (uses get_plot_config() if not provided)
- draw_point(ctx: PlotContext, x: float, y: float, x_max: float, label: str | None = None, zero_at_bottom: bool = False, config: PlotConfig | None = None, point_size: int | None = None) None[source]
Draw a single point with optional label.
- Parameters:
ctx – PlotContext containing plot state
x – X coordinate in data coordinates
y – Y coordinate in data coordinates
x_max – Maximum X value for scaling
label – Optional label text to digital
zero_at_bottom – Whether zero is at bottom of plot (default: False)
config – Optional PlotConfig (uses get_plot_config() if not provided)
point_size – Optional point size override (uses config.point_size if not provided)
- draw_points(ctx: PlotContext, points: list[tuple[float, float, str | None]], x_max: float, zero_at_bottom: bool = False, config: PlotConfig | None = None, point_size: int | None = None) None[source]
Draw multiple points with optional labels.
- Parameters:
ctx – PlotContext containing plot state
points – List of (x, y, label) tuples in data coordinates (label can be None)
x_max – Maximum X value for scaling
zero_at_bottom – Whether zero is at bottom of plot (default: False)
config – Optional PlotConfig (uses get_plot_config() if not provided)
point_size – Optional point size override (uses config.point_size if not provided)
- paintEvent(event) None[source]
Template method for painting. Subclasses can override hook methods instead.
The default implementation provides a structured paintEvent that: 1. Sets up painter and background 2. Creates PlotContext 3. Draws axes 4. Calls hook methods for customization
Override individual hook methods rather than paintEvent for better structure.
- get_y_range() tuple[float, float][source]
Get Y-axis range. Override to provide custom range.
- Returns:
Tuple of (y_max, y_min)
- zero_at_bottom() bool[source]
Specify if zero is at bottom of plot. Override to customize.
- Returns:
True if zero is at bottom, False otherwise
- draw_custom_ticks(ctx: PlotContext, config: PlotConfig) None[source]
Draw custom tick marks. Override to add custom ticks.
- Parameters:
ctx – PlotContext containing plot state
config – PlotConfig for appearance settings
- draw_labels(ctx: PlotContext, config: PlotConfig) None[source]
Draw title and axis labels. Override to customize labels.
- Parameters:
ctx – PlotContext containing plot state
config – PlotConfig for appearance settings
- draw_grid_hook(ctx: PlotContext, config: PlotConfig) None[source]
Draw grid. Override to customize grid drawing.
- Parameters:
ctx – PlotContext containing plot state
config – PlotConfig for appearance settings
- draw_data(ctx: PlotContext, config: PlotConfig) None[source]
Draw plot data (envelope, curve, etc.). Override to draw plot-specific data.
- Parameters:
ctx – PlotContext containing plot state
config – PlotConfig for appearance settings
- get_x_label() str[source]
Get X-axis label. Override to provide label.
- Returns:
X-axis label string
- get_y_label() str[source]
Get Y-axis label. Override to provide label.
- Returns:
Y-axis label string
- abstract envelope_parameters() tuple[numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]], int, int][source]
Envelope parameters