Skip to main content

Bar

Namespace: DISPLIB  ·  Library: Display Library

#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; both call splitCoefficientAndExponent internally to format the tick labels with a configurable number of significant digits.

src/examples/ex_disp_plots/main.cpp
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

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 user input to determine the amount of digits of coefficient shown in the histogram.


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 user input to determine the amount of digits of coefficient shown in the histogram.


splitCoefficientAndExponent(matClassLimitData, iClassAmount, vecCoefficientResults, vecExponentValues)​

splitCoefficientAndExponent takes in QVector value of coefficient and exponent and normalizes them.

Parameters:

  • matClassLimitData : const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & vector input filled with values of class limits.

  • iClassAmount : int amount of classes in the histogram.

  • vecCoefficientResults : Eigen::VectorXd & vector filled with values of coefficient only.

  • vecExponentValues : Eigen::VectorXi & vector filled with values of exponent only.


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 116
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
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;
for (int py = 0; py < barImage.height(); ++py) {
h += close(barImage.pixel(60 + 80 * b + 40, py), steelBlue, 2);

Authors of this file​