Bar
Namespace: DISPLIB · Library: Display Library · Source: disp/plots/bar.h
#include <disp/bar.h>
class DISPLIB::Bar
Bar chart / histogram QWidget rendering Eigen class-limit + frequency vectors with QPainter.
Templated on the value type so callers can pass either integer or floating bin limits. Use setData to install a new dataset and updatePlot to refresh an existing chart in place; each bar is labelled with its class limits in data units.
Bar bar("Amplitude histogram");
VectorXd classLimits(5); // class edges
classLimits << 0.0, 1.0, 2.0, 3.0, 4.0;
VectorXi counts(4); // counts per class
counts << 5, 20, 10, 15;
bar.setData(classLimits, counts, 2); // 2 digits on the axis labels
bar.setXLabel("Amplitude");
bar.setYLabel("Count");
Inheritance
Public Methods
Bar(title, parent)
The constructor for Bar.
Parameters:
-
title : const QString & Title drawn above the bar chart (default empty).
-
parent : *QWidget ** Parent widget (default nullptr).
setData(matClassLimitData, matClassFrequencyData, iPrecisionValue)
Sets new data to the bar chart.
Parameters:
-
matClassLimitData : const Eigen::Matrix< T, Eigen::Dynamic, 1 > & vector input filled with class limits.
-
matClassFrequencyData : const Eigen::Matrix< int, Eigen::Dynamic, 1 > & vector input filled with class frequency to the corresponding class.
-
iPrecisionValue : int significant digits of the class limits on the x axis.
setData(matClassLimitData, matClassFrequencyData, iPrecisionValue)
updatePlot(matClassLimitData, matClassFrequencyData, iPrecisionValue)
Updates the bar plot with the new data.
Parameters:
-
matClassLimitData : const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & vector input filled with class limits.
-
matClassFrequencyData : const Eigen::Matrix< int, Eigen::Dynamic, Eigen::Dynamic > & vector input filled with class frequency to the corresponding class.
-
iPrecisionValue : int significant digits of the class limits on the x axis.
setXLabel(label)
Sets the label of the x axis, e.g.
the quantity and unit of the class limits.
Parameters:
- label : const QString & The x axis label.
setYLabel(label)
Sets the label of the y axis.
Parameters:
- label : const QString & The y axis label.
Example
- Start here: ex_disp_plots — Disp plots: colour maps, bar and spline histograms, line plots, image and time-frequency maps.
- Full source:
src/examples/ex_disp_plots/main.cpp - Build target:
ex_disp_plots(runs under CTest)
Used in examples
ex_disp_plots
Disp plots: colour maps, bar and spline histograms, line plots, image and time-frequency maps.
Bar bar("Amplitude histogram");
VectorXd classLimits(5); // class edges
classLimits << 0.0, 1.0, 2.0, 3.0, 4.0;
VectorXi counts(4); // counts per class
counts << 5, 20, 10, 15;
bar.setData(classLimits, counts, 2); // 2 digits on the axis labels
bar.setXLabel("Amplitude");
bar.setYLabel("Count");
const QImage barImage = render(bar);
// Plot height 300 - 40 - 100 = 160 px and the tallest bar (20 counts) fills it, so heights follow the counts
QList<int> heights;
for (int b = 0; b < 4; ++b) {
int h = 0;
Authors of this file
- Lorenz Esch <lorenz.esch@tu-ilmenau.de>
- Juan GPC <jgarciaprieto@mgh.harvard.edu>
- Andreas Griesshammer <ag@fieldlineinc.com>
- Gabriel Motta <gabrielbenmotta@gmail.com>
- Christoph Dinh <christoph.dinh@mne-cpp.org>