Skip to main content

LinePlot

Namespace: DISPLIB  ·  Library: Display Library  ·  Source: disp/plots/lineplot.h

#include <disp/lineplot.h>

class DISPLIB::LinePlot

Simple x / y line-series QWidget rendered with QPainter (no Qt Charts dependency).

Supports multiple series, a settable title and x / y labels and auto-ranging axes. Series are stored as QVector<double> pairs and re-drawn during paintEvent.

src/examples/ex_disp_plots/main.cpp
QVector<double> x;
QVector<double> y;
for (int i = 0; i <= 100; ++i) {
x.append(i / 100.0);
y.append(std::sin(2.0 * M_PI * x.last()));
}
LinePlot line(x, y, "sin(2 pi t)");
line.setXLabel("t [s]");
line.setYLabel("amplitude");

Inheritance​


Public Methods​

LinePlot(parent)​

Constructs a line series plot.

Parameters:

  • parent : *QWidget ** If parent is nullptr, the new widget becomes a window.

LinePlot(y, title, parent)​

Constructs a line series plot.

Parameters:

  • y : const QVector< double > & The double data vector.

  • title : const QString & Plot title.

  • parent : *QWidget ** If parent is nullptr, the new widget becomes a window.


LinePlot(x, y, title, parent)​

Constructs a line series plot.

Parameters:

  • x : const QVector< double > & X-Axis data to plot.

  • y : const QVector< double > & Y-Axis data to plot.

  • title : const QString & Plot title.

  • parent : *QWidget ** If parent is nullptr, the new widget becomes a window.


~LinePlot()​

Destructs the line series plot.


setTitle(p_sTitle)​

Sets the plot title.

Parameters:

  • p_sTitle : const QString & The title.

setXLabel(p_sXLabel)​

Sets the label of the x axis.

Parameters:

  • p_sXLabel : const QString & The x axis label.

setYLabel(p_sYLabel)​

Sets the label of the y axis.

Parameters:

  • p_sYLabel : const QString & The y axis label.

updateData(y)​

Updates the plot using a given double vector without given X data.

Parameters:

  • y : const QVector< double > & The double data vector.

updateData(x, y)​

Updates the plot using the given vectors.

Parameters:

  • x : const QVector< double > & X-Axis data to plot.

  • y : const QVector< double > & Y-Axis data to plot.


addSeries(x, y, label, color, style)​

Adds a series to the plot; the axes grow to include it and a legend lists the labelled series.

Parameters:

  • x : const QVector< double > & X-Axis data to plot.

  • y : const QVector< double > & Y-Axis data to plot.

  • label : const QString & Legend entry; series without a label are not listed.

  • color : const QColor & Line colour; an invalid colour takes the first palette colour no other series uses.

  • style : Qt::PenStyle Line style, e.g. Qt::DashLine for a series that may coincide with another.


seriesCount()​

Returns the number of series in the plot.

Returns:

  • int — The number of series.

Example​

Used in examples​

ex_disp_plots​

Disp plots: colour maps, bar and spline histograms, line plots, image and time-frequency maps.

src/examples/ex_disp_plots/main.cpp, line 155
LinePlot line(x, y, "sin(2 pi t)");
line.setXLabel("t [s]");
line.setYLabel("amplitude");
const QImage lineImage = render(line);
int top = lineImage.height();
int bottom = 0;
for (int py = 0; py < lineImage.height(); ++py) {
for (int px = 0; px < lineImage.width(); ++px) {
if (close(lineImage.pixel(px, py), steelBlue, 40)) {
top = std::min(top, py);
bottom = std::max(bottom, py);
}
}

ex_spectral​

Multitaper spectra, power spectral density and cross-spectral density of random test signals.

src/examples/ex_spectral/main.cpp, line 95
//Plot hanning window
VectorXd hann = matTaps.row(0).transpose();
LinePlot plotWindow(toVector(hann), "Hanning window");
plotWindow.setXLabel("Sample");
plotWindow.setYLabel("Weight");

ex_connectivity_metrics​

Connectivity metrics on synthetic data with a known coupling.

src/examples/ex_connectivity_metrics/main.cpp, line 320
LinePlot traces;
traces.setTitle("First of 20 trials, channels offset by 4");
traces.setXLabel("Time [ms]");
traces.setYLabel("Amplitude");
for (int ch = 0; ch < 3; ++ch) {
QVector<double> values(ms.size());
for (int t = 0; t < ms.size(); ++t) {
values[t] = settings.at(0).matData(ch, t) - 4.0 * ch;
}
traces.addSeries(ms, values, QStringList{"0: 10 Hz sine + noise", "1: channel 0, 12 ms later, + noise", "2: noise"}[ch]);
}
FigureExporter::save(traces, "trials", "Simulated data: channel 1 repeats channel 0 12 ms later with independent noise; channel 2 is independent noise.");

Also used in ex_dsp_filter, ex_dsp_spectral, ex_averaging, ex_inverse_cmne, ex_inverse_mne, ex_read_evoked, ex_read_raw.

Authors of this file​