base ==== .. py:module:: base .. autoapi-nested-parse:: Base Plot Widget ================ Base class for plot widgets that provides common functionality like shaded curve drawing. Classes ------- .. autoapisummary:: base.PlotContext base.PlotConfig base.BasePlotWidget Module Contents --------------- .. py:class:: PlotContext Context object holding plot state for drawing operations. This eliminates the need to pass multiple parameters repeatedly and provides coordinate conversion helpers. :param painter: QPainter instance for drawing :param left_pad: Left padding of the plot area in pixels :param plot_w: Width of the plot area in pixels :param plot_h: Height of the plot area in pixels :param top_pad: Top padding of the plot area in pixels :param y_max: Maximum Y value in data coordinates :param y_min: Minimum Y value in data coordinates :param zero_y: Y coordinate of the zero line in pixels (optional, calculated if not provided) .. py:attribute:: painter :type: PySide6.QtGui.QPainter .. py:attribute:: left_pad :type: int .. py:attribute:: plot_w :type: int .. py:attribute:: plot_h :type: int .. py:attribute:: top_pad :type: int .. py:attribute:: y_max :type: float .. py:attribute:: y_min :type: float .. py:attribute:: zero_y :type: Optional[float] :value: None .. py:method:: value_to_x(value: float, x_max: float) -> float Convert X data value to pixel coordinate. :param value: X value in data coordinates (0 to x_max) :param x_max: Maximum X value in data coordinates :return: X coordinate in pixels .. py:method:: value_to_y(value: float, zero_at_bottom: bool = False) -> float Convert Y data value to pixel coordinate. :param value: Y value in data coordinates :param zero_at_bottom: If True, zero is at bottom of plot (default: False, uses y_max/y_min scaling) :return: Y coordinate in pixels .. py:class:: PlotConfig Configuration for plot appearance. Centralizes colors, fonts, padding, and other visual settings. .. py:attribute:: top_padding :type: int :value: 50 .. py:attribute:: bottom_padding :type: int :value: 80 .. py:attribute:: left_padding :type: int :value: 80 .. py:attribute:: right_padding :type: int :value: 50 .. py:attribute:: title_font_size :type: int :value: 16 .. py:attribute:: label_font_size :type: int :value: 10 .. py:attribute:: tick_font_size :type: int :value: 8 .. py:attribute:: title_color :type: PySide6.QtGui.QColor .. py:attribute:: label_color :type: PySide6.QtGui.QColor .. py:attribute:: grid_color :type: PySide6.QtGui.QColor .. py:attribute:: envelope_color :type: PySide6.QtGui.QColor .. py:attribute:: axis_color :type: PySide6.QtGui.QColor .. py:attribute:: point_color :type: PySide6.QtGui.QColor .. py:attribute:: point_size :type: int :value: 6 .. py:attribute:: envelope_line_width :type: int :value: 2 .. py:attribute:: axis_line_width :type: int :value: 1 .. py:attribute:: grid_line_width :type: int :value: 1 .. py:attribute:: font_family :type: str :value: 'JD LCD Rounded' .. py:class:: BasePlotWidget Bases: :py:obj:`PySide6.QtWidgets.QWidget` Base class for plot widgets that provides common shading functionality. .. py:method:: draw_background(painter: PySide6.QtGui.QPainter) -> None Draw the background gradient for the plot. :param painter: QPainter instance .. py:method:: set_dimensions(height: int, width: int) Set address fixed size for the widget (or use layouts as needed) .. py:method:: 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 Draw a shaded fill under the curve with a gradient. :param painter: QPainter instance :param path: QPainterPath representing the curve (may or may not be closed) :param top_pad: Top padding of the plot area :param plot_h: Height of the plot area :param zero_y: Y coordinate of the zero line :param left_pad: Left padding of the plot area :param plot_w: Width of the plot area .. py:method:: 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: Optional[Callable[[float], float]] = None) -> None Draw grid lines matching FilterPlot style. :param painter: QPainter instance :param top_pad: Top padding of the plot area :param plot_h: Height of the plot area :param left_pad: Left padding of the plot area :param plot_w: Width of the plot area :param num_vertical_lines: Number of vertical grid lines (default: 6) :param num_horizontal_lines: Number of horizontal grid lines (default: 5) :param y_min: Minimum Y value for scaling (default: 0.0) :param y_max: Maximum Y value for scaling (default: 1.0) :param y_callback: Optional callback function(y_val) -> y_pixel for custom Y coordinate calculation .. py:method:: draw_title(painter: PySide6.QtGui.QPainter, title: str, left_pad: int, plot_w: int, top_pad: int, config: Optional[PlotConfig] = None) -> None 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. :param painter: QPainter instance :param title: Title text to digital :param left_pad: Left padding of the plot area :param plot_w: Width of the plot area :param top_pad: Top padding of the plot area :param config: Optional PlotConfig (uses get_plot_config() if not provided) .. py:method:: draw_x_axis_label(painter: PySide6.QtGui.QPainter, label: str, left_pad: int, plot_w: int, plot_h: int, top_pad: int, config: Optional[PlotConfig] = None) -> None 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. :param painter: QPainter instance :param label: Label text to digital :param left_pad: Left padding of the plot area :param plot_w: Width of the plot area :param plot_h: Height of the plot area :param top_pad: Top padding of the plot area :param config: Optional PlotConfig (uses get_plot_config() if not provided) .. py:method:: draw_y_axis_label(painter: PySide6.QtGui.QPainter, label: str, left_pad: int, plot_h: int, top_pad: int, config: Optional[PlotConfig] = None) -> None 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. :param painter: QPainter instance :param label: Label text to digital :param left_pad: Left padding of the plot area :param plot_h: Height of the plot area :param top_pad: Top padding of the plot area :param config: Optional PlotConfig (uses get_plot_config() if not provided) .. py:method:: set_pen(painter: PySide6.QtGui.QPainter) -> PySide6.QtGui.QPen Set up pens and fonts for plotting. :param painter: QPainter instance :return: QPen for drawing axes .. py:method:: plot_dimensions(top_padding: int = 50, bottom_padding: int = 50, left_padding: int = 80, right_padding: int = 50) -> tuple[int, int, int, int] Get plot area dimensions. :param top_padding: Top padding (default: 50) :param bottom_padding: Bottom padding (default: 50) :param left_padding: Left padding (default: 80) :param right_padding: Right padding (default: 50) :return: Tuple of (left_pad, plot_h, plot_w, top_pad) .. py:method:: 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 Create a PlotContext from current widget dimensions and provided parameters. This is a convenience method that combines plot_dimensions() with PlotContext creation. :param painter: QPainter instance for drawing :param top_padding: Top padding (default: 50) :param bottom_padding: Bottom padding (default: 50) :param left_padding: Left padding (default: 80) :param right_padding: Right padding (default: 50) :param y_max: Maximum Y value in data coordinates (default: 1.0) :param y_min: Minimum Y value in data coordinates (default: 0.0) :return: PlotContext instance .. py:method:: calculate_zero_y(top_pad: int, plot_h: int, y_max: float, y_min: float, zero_at_bottom: bool = False) -> float Calculate the Y coordinate of the zero line. :param top_pad: Top padding of the plot area :param plot_h: Height of the plot area :param y_max: Maximum Y value :param y_min: Minimum Y value :param zero_at_bottom: If True, zero line is at bottom of plot (default: False, calculated from y_max/y_min) :return: Y coordinate of the zero line .. py:method:: 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 Draw axes (Y-axis and X-axis at zero line). :param axis_pen: Pen for drawing axes :param left_pad: Left padding of the plot area :param painter: QPainter instance :param plot_h: Height of the plot area :param plot_w: Width of the plot area :param top_pad: Top padding of the plot area :param y_max: Maximum Y value :param y_min: Minimum Y value :param zero_at_bottom: If True, zero line is at bottom of plot (default: False) :return: Y coordinate of the zero line .. py:method:: draw_title_ctx(ctx: PlotContext, title: str, config: Optional[PlotConfig] = None) -> None Draw a centered title at the top of the plot using PlotContext. :param ctx: PlotContext containing plot state :param title: Title text to digital :param config: Optional PlotConfig (uses get_plot_config() if not provided) .. py:method:: draw_x_axis_label_ctx(ctx: PlotContext, label: str, config: Optional[PlotConfig] = None) -> None Draw a centered X-axis label at the bottom of the plot using PlotContext. :param ctx: PlotContext containing plot state :param label: Label text to digital :param config: Optional PlotConfig (uses get_plot_config() if not provided) .. py:method:: draw_y_axis_label_ctx(ctx: PlotContext, label: str, config: Optional[PlotConfig] = None) -> None Draw a rotated Y-axis label on the left side of the plot using PlotContext. :param ctx: PlotContext containing plot state :param label: Label text to digital :param config: Optional PlotConfig (uses get_plot_config() if not provided) .. py:method:: draw_axes_ctx(ctx: PlotContext, zero_at_bottom: bool = False, config: Optional[PlotConfig] = None) -> PlotContext Draw axes (Y-axis and X-axis at zero line) using PlotContext. Updates and returns the context with zero_y calculated. :param ctx: PlotContext containing plot state :param zero_at_bottom: If True, zero line is at bottom of plot (default: False) :param config: Optional PlotConfig (uses get_plot_config() if not provided) :return: Updated PlotContext with zero_y set .. py:method:: draw_shaded_curve_ctx(ctx: PlotContext, path: PySide6.QtGui.QPainterPath) -> None Draw a shaded fill under the curve with a gradient using PlotContext. :param ctx: PlotContext containing plot state (must have zero_y set) :param path: QPainterPath representing the curve (may or may not be closed) .. py:method:: draw_x_axis_ticks(ctx: PlotContext, tick_values: list[float], tick_labels: Optional[list[str]] = None, tick_length: int = 5, label_offset: int = 20, position: str = 'bottom', x_max: Optional[float] = None, config: Optional[PlotConfig] = None) -> None Draw X-axis tick marks and labels. :param ctx: PlotContext containing plot state :param tick_values: List of X values (in data coordinates) for tick positions :param tick_labels: Optional list of label strings (defaults to formatted tick_values) :param tick_length: Length of tick marks in pixels (default: 5) :param label_offset: Vertical offset for labels in pixels (default: 20) :param position: Where to draw ticks - "bottom", "top", or "zero" for zero line (default: "bottom") :param x_max: Maximum X value for scaling (required if tick_values are in data coordinates) :param config: Optional PlotConfig (uses get_plot_config() if not provided) .. py:method:: draw_y_axis_ticks(ctx: PlotContext, tick_values: list[float], tick_labels: Optional[list[str]] = None, tick_length: int = 5, label_offset: int = 45, zero_at_bottom: bool = False, config: Optional[PlotConfig] = None) -> None Draw Y-axis tick marks and labels. :param ctx: PlotContext containing plot state :param tick_values: List of Y values (in data coordinates) for tick positions :param tick_labels: Optional list of label strings (defaults to formatted tick_values) :param tick_length: Length of tick marks in pixels (default: 5) :param label_offset: Horizontal offset for labels in pixels (default: 45) :param zero_at_bottom: Whether zero is at bottom of plot (default: False) :param config: Optional PlotConfig (uses get_plot_config() if not provided) .. py:method:: draw_grid_ctx(ctx: PlotContext, x_ticks: Optional[list[float]] = None, y_ticks: Optional[list[float]] = None, x_max: Optional[float] = None, num_vertical_lines: Optional[int] = 6, num_horizontal_lines: Optional[int] = 5, zero_at_bottom: bool = False, y_callback: Optional[Callable[[float], float]] = None, config: Optional[PlotConfig] = None) -> None Draw grid lines with optional custom tick positions using PlotContext. :param ctx: PlotContext containing plot state :param x_ticks: Custom X tick positions (in data coordinates), overrides num_vertical_lines :param y_ticks: Custom Y tick positions (in data coordinates), overrides num_horizontal_lines :param x_max: Maximum X value for scaling (required if x_ticks provided) :param num_vertical_lines: Number of vertical grid lines (if x_ticks not provided, default: 6) :param num_horizontal_lines: Number of horizontal grid lines (if y_ticks not provided, default: 5) :param zero_at_bottom: Whether zero is at bottom of plot (default: False) :param y_callback: Optional callback function(y_val) -> y_pixel for custom Y coordinate calculation :param config: Optional PlotConfig (uses get_plot_config() if not provided) .. py:method:: value_to_x_pixel(ctx: PlotContext, value: float, x_max: float) -> float Convert X data value to pixel coordinate using PlotContext. :param ctx: PlotContext containing plot state :param value: X value in data coordinates (0 to x_max) :param x_max: Maximum X value in data coordinates :return: X coordinate in pixels .. py:method:: value_to_y_pixel(ctx: PlotContext, value: float, zero_at_bottom: bool = False) -> float Convert Y data value to pixel coordinate using PlotContext. :param ctx: PlotContext containing plot state :param value: Y value in data coordinates :param zero_at_bottom: If True, zero is at bottom of plot (default: False) :return: Y coordinate in pixels .. py:method:: get_plot_config() -> PlotConfig Get plot configuration. Override to customize appearance. :return: PlotConfig instance .. py:method:: get_title_font(config: Optional[PlotConfig] = None) -> PySide6.QtGui.QFont Get font for plot title. :param config: Optional PlotConfig (uses get_plot_config() if not provided) :return: QFont for title .. py:method:: get_label_font(config: Optional[PlotConfig] = None) -> PySide6.QtGui.QFont Get font for axis labels. :param config: Optional PlotConfig (uses get_plot_config() if not provided) :return: QFont for labels .. py:method:: get_tick_font(config: Optional[PlotConfig] = None) -> PySide6.QtGui.QFont Get font for tick labels. :param config: Optional PlotConfig (uses get_plot_config() if not provided) :return: QFont for ticks .. py:method:: get_envelope_pen(config: Optional[PlotConfig] = None) -> PySide6.QtGui.QPen Get pen for drawing envelope curves. :param config: Optional PlotConfig (uses get_plot_config() if not provided) :return: QPen for envelope .. py:method:: get_axis_pen(config: Optional[PlotConfig] = None) -> PySide6.QtGui.QPen Get pen for drawing axes. :param config: Optional PlotConfig (uses get_plot_config() if not provided) :return: QPen for axes .. py:method:: get_grid_pen(config: Optional[PlotConfig] = None) -> PySide6.QtGui.QPen Get pen for drawing grid lines. :param config: Optional PlotConfig (uses get_plot_config() if not provided) :return: QPen for grid .. py:method:: get_point_pen(config: Optional[PlotConfig] = None) -> PySide6.QtGui.QPen Get pen for drawing points. :param config: Optional PlotConfig (uses get_plot_config() if not provided) :return: QPen for points .. py:method:: 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: Optional[PlotConfig] = None) -> PySide6.QtGui.QPainterPath Draw a curve from an array of Y values. :param ctx: PlotContext containing plot state :param y_values: Array or list of Y values (in data coordinates) :param x_max: Maximum X value (total time/duration in data coordinates) :param sample_rate: Sample rate for converting indices to time (default: 1.0) :param max_points: Maximum number of points to draw (default: 500) :param zero_at_bottom: Whether zero is at bottom of plot (default: False) :param config: Optional PlotConfig (uses get_plot_config() if not provided) :return: QPainterPath representing the curve .. py:method:: draw_curve_from_points(ctx: PlotContext, points: list[tuple[float, float]], x_max: float, zero_at_bottom: bool = False, config: Optional[PlotConfig] = None) -> PySide6.QtGui.QPainterPath Draw a curve from a list of (x, y) tuples in data coordinates. :param ctx: PlotContext containing plot state :param points: List of (x, y) tuples in data coordinates :param x_max: Maximum X value for scaling :param zero_at_bottom: Whether zero is at bottom of plot (default: False) :param config: Optional PlotConfig (uses get_plot_config() if not provided) :return: QPainterPath representing the curve .. py:method:: 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: Optional[PlotConfig] = None) -> None Draw a curve with shaded fill from an array of Y values. :param ctx: PlotContext containing plot state (must have zero_y set) :param y_values: Array or list of Y values (in data coordinates) :param x_max: Maximum X value (total time/duration in data coordinates) :param sample_rate: Sample rate for converting indices to time (default: 1.0) :param max_points: Maximum number of points to draw (default: 500) :param zero_at_bottom: Whether zero is at bottom of plot (default: False) :param config: Optional PlotConfig (uses get_plot_config() if not provided) .. py:method:: draw_point(ctx: PlotContext, x: float, y: float, x_max: float, label: Optional[str] = None, zero_at_bottom: bool = False, config: Optional[PlotConfig] = None, point_size: Optional[int] = None) -> None Draw a single point with optional label. :param ctx: PlotContext containing plot state :param x: X coordinate in data coordinates :param y: Y coordinate in data coordinates :param x_max: Maximum X value for scaling :param label: Optional label text to digital :param zero_at_bottom: Whether zero is at bottom of plot (default: False) :param config: Optional PlotConfig (uses get_plot_config() if not provided) :param point_size: Optional point size override (uses config.point_size if not provided) .. py:method:: draw_points(ctx: PlotContext, points: list[tuple[float, float, Optional[str]]], x_max: float, zero_at_bottom: bool = False, config: Optional[PlotConfig] = None, point_size: Optional[int] = None) -> None Draw multiple points with optional labels. :param ctx: PlotContext containing plot state :param points: List of (x, y, label) tuples in data coordinates (label can be None) :param x_max: Maximum X value for scaling :param zero_at_bottom: Whether zero is at bottom of plot (default: False) :param config: Optional PlotConfig (uses get_plot_config() if not provided) :param point_size: Optional point size override (uses config.point_size if not provided) .. py:method:: paintEvent(event) -> None 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. .. py:method:: get_y_range() -> tuple[float, float] Get Y-axis range. Override to provide custom range. :return: Tuple of (y_max, y_min) .. py:method:: zero_at_bottom() -> bool Specify if zero is at bottom of plot. Override to customize. :return: True if zero is at bottom, False otherwise .. py:method:: draw_custom_ticks(ctx: PlotContext, config: PlotConfig) -> None Draw custom tick marks. Override to add custom ticks. :param ctx: PlotContext containing plot state :param config: PlotConfig for appearance settings .. py:method:: draw_labels(ctx: PlotContext, config: PlotConfig) -> None Draw title and axis labels. Override to customize labels. :param ctx: PlotContext containing plot state :param config: PlotConfig for appearance settings .. py:method:: draw_grid_hook(ctx: PlotContext, config: PlotConfig) -> None Draw grid. Override to customize grid drawing. :param ctx: PlotContext containing plot state :param config: PlotConfig for appearance settings .. py:method:: draw_data(ctx: PlotContext, config: PlotConfig) -> None Draw plot data (envelope, curve, etc.). Override to draw plot-specific data. :param ctx: PlotContext containing plot state :param config: PlotConfig for appearance settings .. py:method:: get_title() -> str Get plot title. Override to provide title. :return: Title string .. py:method:: get_x_label() -> str Get X-axis label. Override to provide label. :return: X-axis label string .. py:method:: get_y_label() -> str Get Y-axis label. Override to provide label. :return: Y-axis label string .. py:method:: envelope_parameters() -> tuple[numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]], int, int] :abstractmethod: Envelope parameters