Skip to main content

Line Plot

Render a 2D line plot from two Eigen vectors — the most common plot type for time series, function graphs, and signal visualization.

API

template <typename DerivedX, typename DerivedY>
void PlotView::plot(const Eigen::MatrixBase<DerivedX>& x,
const Eigen::MatrixBase<DerivedY>& y);

Accepts any Eigen expression (vectors, blocks, array expressions). Data is cast to float and interleaved into a GPU vertex buffer. Bounding box is computed automatically.

Methods

MethodDescription
plot(x, y)Set line data from two equal-length vectors
setLineColor(rgba)Set line colour as Eigen::Vector4f (RGBA, 0–1)
setBackgroundColor(rgba)Set viewport background colour

Example

#include <skigen/plot/plotview.h>
#include <Eigen/Core>
#include <QApplication>
#include <numbers>

int main(int argc, char* argv[]) {
QApplication app(argc, argv);

int n = 500;
Eigen::VectorXf x = Eigen::VectorXf::LinSpaced(n, 0.f,
4.f * std::numbers::pi_v<float>);
Eigen::VectorXf y = x.array().sin();

Skigen::Plot::PlotView view;
view.plot(x, y);
view.setLineColor({0.2f, 0.8f, 0.4f, 1.0f});
view.resize(800, 500);
view.show();

return app.exec();
}

Eigen Expression Support

Any Eigen expression that evaluates to a vector works:

Eigen::MatrixXf data = Eigen::MatrixXf::Random(100, 2);
view.plot(data.col(0), data.col(1)); // columns
view.plot(data.col(0).head(50), data.col(1).head(50)); // sub-ranges
view.plot(data.col(0), data.col(0).array().square()); // array expressions

std::ranges Bridge

Plot data from any contiguous range via mapRange():

std::vector<float> x_data = {0, 1, 2, 3, 4};
std::vector<float> y_data = {0, 1, 4, 9, 16};

view.plot(Skigen::Plot::mapRange(x_data),
Skigen::Plot::mapRange(y_data));

Performance

The line is rendered as a LineStrip topology on the GPU via QRhi. Data upload uses dynamic vertex buffers — buffers grow automatically when datasets exceed the current capacity.