AZPlottingClass

The main plotting widget class. Inherits from QWidget and wraps QCustomPlot with a simplified API for scientific data visualization.

#include "AZPlottingClass.h"

class AZPlottingClass : public QWidget

Constructor

AZPlottingClass(QWidget *parent = nullptr)

Creates a new plotting widget. Pass a parent widget for automatic memory management, or nullptr for a standalone window.

Data Methods

addDataSeries

int addDataSeries(const QVector<double> &x, const QVector<double> &y, const QString &name = QString(), const QColor &color = Qt::blue, LineStyle style = LineStyle::Solid, double lineWidth = 1.5)

Adds a line series to the primary Y-axis. Returns a series ID for later reference.

ParameterTypeDescription
x QVector<double> X-axis data values
y QVector<double> Y-axis data values (must match x size)
name QString Legend label (empty to hide from legend)
color QColor Line color
style LineStyle Solid, Dashed, Dotted, DashDot, or None
lineWidth double Line width in pixels
Returns: int - Series ID for use with appendData(), removeSeries(), etc.
Tip
Multiple overloads exist for different data formats: std::vector, std::initializer_list, raw pointers, and Y-only (auto-generates X as 0, 1, 2...).

addDataSeriesToY2

int addDataSeriesToY2(const QVector<double> &x, const QVector<double> &y, const QString &name = QString(), const QColor &color = Qt::red, LineStyle style = LineStyle::Solid, double lineWidth = 1.5)

Adds a line series to the secondary Y-axis (right side). Automatically enables and shows the Y2 axis. Useful for Bode plots or comparing data with different units.

addScatterSeries

int addScatterSeries(const QVector<double> &x, const QVector<double> &y, const QString &name = QString(), const QColor &color = Qt::red, double markerSize = 6.0, MarkerStyle marker = MarkerStyle::Circle)

Adds a scatter plot (markers only, no connecting lines).

ParameterTypeDescription
marker MarkerStyle Circle, Square, Diamond, Triangle, Cross, Plus, or Star
markerSize double Marker diameter in pixels

addLineMarkerSeries

int addLineMarkerSeries(const QVector<double> &x, const QVector<double> &y, const QString &name = QString(), const QColor &color = Qt::blue, LineStyle lineStyle = LineStyle::Solid, MarkerStyle marker = MarkerStyle::Circle, double lineWidth = 1.5, double markerSize = 6.0)

Adds a series with both connecting lines and markers at each data point.

addBarSeries

int addBarSeries(const QVector<double> &x, const QVector<double> &y, const QString &name = QString(), const QColor &color = Qt::blue, double width = 0.8)

Adds a bar chart. The width parameter controls bar width relative to spacing.

appendData

void appendData(int seriesId, double x, double y) void appendData(int seriesId, const QVector<double> &x, const QVector<double> &y)

Appends data points to an existing series without clearing. Designed for real-time data streaming. Use with replotQueued() for efficient high-frequency updates.

clearData / removeSeries

void clearData() void removeSeries(int id)

clearData() removes all series. removeSeries(id) removes a specific series by ID.

setScrollingWindow

void setScrollingWindow(int seriesId, double windowWidth)

Enables auto-scrolling for real-time plots. The X-axis will automatically pan to show the last windowWidth units of data. Call clearScrollingWindow(seriesId) to disable.

Axis Methods

setXAxisScale / setYAxisScale / setY2AxisScale

void setXAxisScale(ScaleType type) void setYAxisScale(ScaleType type) void setY2AxisScale(ScaleType type)

Sets the axis scale type:

  • ScaleType::Linear - Standard linear scale
  • ScaleType::Logarithmic - Base-10 logarithmic (positive values only)
  • ScaleType::SymLog - Symmetric logarithmic (handles negative values)

setXAxisRange / setYAxisRange / setY2AxisRange

void setXAxisRange(double min, double max) void setYAxisRange(double min, double max) void setY2AxisRange(double min, double max)

Manually sets the visible range for an axis.

autoScaleX / autoScaleY / autoScaleAll

void autoScaleX() void autoScaleY() void autoScaleAll()

Automatically fits axis ranges to encompass all visible data with a small margin.

setXAxisLabel / setYAxisLabel / setY2AxisLabel / setTitle

void setXAxisLabel(const QString &label) void setYAxisLabel(const QString &label) void setY2AxisLabel(const QString &label) void setTitle(const QString &title)

Sets axis labels and plot title. Supports UTF-8 for units (e.g., "dB/dt (nV/m²)").

setXAxisInverted / setYAxisInverted

void setXAxisInverted(bool inverted) void setYAxisInverted(bool inverted)

Inverts an axis (useful for depth plots where depth increases downward).

setLinearThreshold / setLinearWidth

void setLinearThreshold(double value) void setLinearWidth(double value)

Configures the SymLog transform. linearThreshold defines the range around zero that uses linear scaling. linearWidth controls how much visual space that linear region occupies.

Appearance Methods

applyProfessionalStyle / applyDarkTheme

void applyProfessionalStyle() void applyDarkTheme()

Applies preset themes. applyProfessionalStyle() sets preset fonts and colors with subtle colors. applyDarkTheme() switches to a dark background suitable for extended viewing.

setGridVisible

void setGridVisible(bool major, bool minor)

Shows or hides major and minor grid lines.

setLegendVisible / setLegendPosition

void setLegendVisible(bool visible) void setLegendPosition(Qt::Alignment alignment)

Controls legend visibility and position (e.g., Qt::AlignTop | Qt::AlignRight).

setCrosshairEnabled

void setCrosshairEnabled(bool enabled)

Enables a crosshair cursor that follows the mouse with coordinate readout.

setStatsVisible / setStatsPosition

void setStatsVisible(bool visible) void setStatsPosition(Qt::Alignment alignment)

Shows an overlay with data statistics (min, max, mean) for all visible series.

Annotation Methods

addVerticalLine / addHorizontalLine

void addVerticalLine(double x, const QColor &color = Qt::red, const QString &label = QString(), double width = 1.5) void addHorizontalLine(double y, const QColor &color = Qt::red, const QString &label = QString(), double width = 1.5)

Adds marker lines that span the entire plot area. Useful for threshold indicators.

addTextAnnotation

int addTextAnnotation(double x, double y, const QString &text, const QColor &color = Qt::black, int fontSize = 10, Qt::Alignment alignment = Qt::AlignCenter)

Adds a text label at plot coordinates. Returns an annotation ID.

addArrowAnnotation

int addArrowAnnotation(double x1, double y1, double x2, double y2, const QColor &color = Qt::black, double lineWidth = 1.5, bool doubleEnded = false)

Adds an arrow from (x1, y1) to (x2, y2). Set doubleEnded for bidirectional arrows.

addRectAnnotation / addEllipseAnnotation

int addRectAnnotation(double x1, double y1, double x2, double y2, ...) int addEllipseAnnotation(double cx, double cy, double rx, double ry, ...)

Adds shape annotations with configurable border and fill colors.

addLabeledEllipse / addLabeledRect

int addLabeledEllipse(double cx, double cy, double rx, double ry, const QString &text, const QColor &color = Qt::red, double lineWidth = 1.5) int addLabeledRect(double x1, double y1, double x2, double y2, const QString &text, const QColor &color = Qt::red, double lineWidth = 1.5)

Convenience methods that combine a shape with a centered text label.

Export Methods

exportToPNG / exportToPDF

bool exportToPNG(const QString &path, int width = 1200, int height = 800, double scale = 2.0) bool exportToPDF(const QString &path, int width = 1200, int height = 800)

Exports the plot to an image file. The scale parameter for PNG creates a higher-resolution image (2.0 = retina/HiDPI). Returns true on success.

copyToClipboard

void copyToClipboard()

Copies the current plot image to the system clipboard.

saveState / loadState

QJsonObject saveState() const bool loadState(const QJsonObject &state)

Serializes/deserializes the complete plot state (data, ranges, styles, annotations) to JSON. Useful for session persistence.

saveStateToFile / loadStateFromFile

bool saveStateToFile(const QString &path) const bool loadStateFromFile(const QString &path)

Convenience methods that save/load state directly to/from a JSON file.

Interaction Methods

setInteractive

void setInteractive(bool zoomEnabled, bool panEnabled)

Enables or disables mouse zoom and pan interactions.

resetZoom / zoomBack

void resetZoom() void zoomBack()

resetZoom() restores the original view. zoomBack() pops the last zoom state from history (also triggered by right-click).

plot()

QCustomPlot* plot()

Returns the underlying QCustomPlot instance for advanced customization beyond this wrapper's API.