Annotations
Horizontal/vertical lines, text labels, rectangles, ellipses, and arrows.
Annotation Types
Source Code
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <cmath>
#include "AZPlottingClass.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.setWindowTitle("Annotations Demo");
window.resize(800, 600);
QVBoxLayout *layout = new QVBoxLayout(&window);
layout->setContentsMargins(0, 0, 0, 0);
AZPlottingClass *plot = new AZPlottingClass(&window);
layout->addWidget(plot);
// Generate a signal with features
QVector<double> x, y;
for (int i = 0; i < 500; ++i) {
double t = i * 0.02;
x.append(t);
double signal = std::sin(t * 2) * std::exp(-t * 0.1);
signal += 0.3 * std::sin(t * 7) * std::exp(-t * 0.15);
signal += 0.5 * std::exp(-std::pow(t - 4.0, 2) / 0.5);
y.append(signal);
}
plot->addDataSeries(x, y, "Signal", Qt::blue);
// Horizontal lines
plot->addHorizontalLine(0.0, QColor(150, 150, 150), "Zero", 1.0);
plot->addHorizontalLine(0.6, Qt::red, "Threshold", 1.5);
// Vertical lines
plot->addVerticalLine(0.0, Qt::blue, "t=0");
plot->addVerticalLine(4.0, QColor(76, 175, 80), "Peak", 1.5);
plot->addVerticalLine(2.0, QColor(156, 39, 176), "Early", 1.0);
// Shaded region
plot->addRectAnnotation(0.0, -2.0, 2.0, 2.0,
Qt::transparent,
QColor(33, 150, 243, 40));
// Text annotations
plot->addTextAnnotation(4.0, 0.85, "Local Maximum", Qt::black, 10);
plot->addTextAnnotation(1.0, 1.3, "Early Time Window", QColor(33, 150, 243), 11);
// Ellipse annotation
plot->addEllipseAnnotation(3.5, 0.3, 5.0, 1.0,
QColor(255, 152, 0),
QColor(255, 152, 0, 30),
2.0);
// Arrow annotation
plot->addArrowAnnotation(6.0, 0.8, 4.3, 0.6, Qt::darkGray, 1.5);
// Configure plot
plot->setTitle("Annotation Examples");
plot->setXAxisLabel("Time (s)");
plot->setYAxisLabel("Amplitude");
plot->applyProfessionalStyle();
plot->setInteractive(true, true);
plot->setCrosshairEnabled(true);
plot->setGridVisible(true, true);
plot->autoScaleAll();
plot->setYAxisRange(-1.2, 1.5);
window.show();
return app.exec();
}
Annotation Methods
// Horizontal/Vertical lines
plot->addHorizontalLine(y, color, label, width);
plot->addVerticalLine(x, color, label, width);
// Text
plot->addTextAnnotation(x, y, text, color, fontSize);
// Shapes
plot->addRectAnnotation(x1, y1, x2, y2, borderColor, fillColor);
plot->addEllipseAnnotation(x1, y1, x2, y2, borderColor, fillColor, width);
plot->addArrowAnnotation(x1, y1, x2, y2, color, width);