AZPlotGrid

A grid container for multiple AZPlottingClass subplots. Provides linked axis support (synchronized zoom/pan across plots) and bulk operations.

#include "AZPlotGrid.h"

class AZPlotGrid : public QWidget

Quick Example

// Create a 2x2 grid of plots
AZPlotGrid *grid = new AZPlotGrid(2, 2, parent);

// Access individual plots by row/col
grid->plot(0, 0)->addDataSeries(x1, y1, "Top-left");
grid->plot(0, 1)->addDataSeries(x2, y2, "Top-right");
grid->plot(1, 0)->addDataSeries(x3, y3, "Bottom-left");
grid->plot(1, 1)->addDataSeries(x4, y4, "Bottom-right");

// Link X-axes: zoom/pan one plot affects all
grid->linkXAxes(true);

// Apply theme to all plots at once
grid->applyProfessionalStyle();

Constructor

AZPlotGrid(int rows, int cols, QWidget *parent = nullptr)

Creates an mxn grid of AZPlottingClass widgets.

ParameterTypeDescription
rows int Number of rows in the grid
cols int Number of columns in the grid
parent QWidget* Parent widget for ownership

Access Methods

plot (by row/col)

AZPlottingClass* plot(int row, int col)

Returns the plot at the specified row and column (0-indexed). Returns nullptr if out of bounds.

plot (by index)

AZPlottingClass* plot(int index)

Returns the plot at a linear index (row-major order). Useful for iteration.

rowCount / colCount / plotCount

int rowCount() const int colCount() const int plotCount() const

Returns grid dimensions and total number of plots.

Axis Linking

When axes are linked, zooming or panning on one subplot automatically applies the same transformation to all other subplots. This is essential for comparing related datasets across multiple views.

linkXAxes

void linkXAxes(bool linked = true)

Links X-axes across all subplots. When linked, horizontal zoom/pan on any plot affects all plots.

linkYAxes

void linkYAxes(bool linked = true)

Links Y-axes across all subplots. When linked, vertical zoom/pan on any plot affects all plots.

linkAllAxes

void linkAllAxes(bool linked = true)

Links both X and Y axes across all subplots.

xAxesLinked / yAxesLinked

bool xAxesLinked() const bool yAxesLinked() const

Query whether axes are currently linked.

Use Case: Multi-Component TEM
When viewing X, Y, Z components of TEM data, link X-axes (time) so you can zoom into a specific time window and see all components aligned. Leave Y-axes independent since amplitudes may differ.

Bulk Operations

Apply settings to all subplots at once:

applyProfessionalStyle / applyDarkTheme

void applyProfessionalStyle() void applyDarkTheme()

Applies the theme to all subplots.

setAllInteractive

void setAllInteractive(bool zoom, bool pan)

Enables or disables zoom and pan on all subplots.

setAllGridVisible

void setAllGridVisible(bool major, bool minor)

Sets grid visibility on all subplots.

Layout

setSpacing

void setSpacing(int spacing)

Sets the spacing between subplots in pixels.

setMargins

void setMargins(int left, int top, int right, int bottom)

Sets the outer margins of the grid container.

Export

exportToPNG

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

Exports the entire grid as a single PNG image. Each subplot is rendered at (width/cols) x (height/rows) size.

exportToPDF

bool exportToPDF(const QString &path, int width = 1600, int height = 1200)

Exports the grid to PDF format.

State Persistence

saveState / loadState

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

Serializes/deserializes the entire grid state including all subplot states, axis linking settings, and layout configuration.

saveStateToFile / loadStateFromFile

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

File-based convenience methods for state persistence.

Signals

void subplotRangeChanged(int row, int col, double xMin, double xMax, double yMin, double yMax)

Emitted when any subplot's visible range changes. Useful for synchronizing external UI elements.