31 #ifndef __TWIG_LIBRARY__
32 #define __TWIG_LIBRARY__
47 std::vector<double> bins;
62 bins.resize(n+1);
double step = (
max-
min)/n;
63 for(
int i = 0; i <=n; i++){ bins[i] =
min + i*step;}
69 auto it = std::lower_bound(bins.begin(), bins.end(), value);
70 return it-bins.begin()-1;
73 int nbins(){
return bins.size()-1;}
75 double center(
int bin){
return bins[bin] + 0.5*(bins[bin+1]-bins[bin]);}
77 double min(){
return bins[0];}
79 double max(){
return bins[bins.size()-1];}
101 h1d(
int n,
double min,
double max){
110 h1d(
int __id,
int n,
double min,
double max){
149 h1d h(buffer[0].
id(), buffer[0].
x.
nbins(), buffer[0].x.min(),buffer[0].x.max());
151 for(
int bin = 0; bin < buffer[0].x.nbins(); bin++){
153 for(
int j = 0; j < (int) buffer.size(); j++){
154 content += buffer[j].content(bin);
167 static std::vector<h1d>
declare(
int count,
int bins,
double xmin,
double xmax){
168 std::vector<h1d> buffer;
169 for(
int j = 0; j < count; j++){
170 h1d h(100+j,bins,xmin,xmax);
171 buffer.push_back(std::move(h));
178 std::vector<double> data;
184 int index = screen.find_first_of(
"┤");
187 << asciichart.height(25).offset(4).Plot();
189 std::cout <<
"\033[38;5;45m";
190 for(
int i = 0; i < (index-52); i++) std::cout <<
" ";
191 std::cout <<
"\u2514\u252C";
192 for(
int i = 0; i <
x.
nbins()/4; i++) std::cout <<
"\u2500\u2500\u2500\u252C";
194 for(
int i = 0; i < (index-51); i++) std::cout <<
" ";
195 std::cout <<
x.
min();
196 for(
int i = 0; i <
x.
nbins()-4; i++) std::cout <<
" ";
197 std::cout <<
x.
max() <<
"\033[0m" <<
'\n';
ASCII chart renderer for plotting data series in the terminal.
Asciichart & height(double height)
Set the height of the chart in data units.
std::string Plot()
Generate and return the ASCII chart as a string.
Asciichart & offset(size_t offset)
Set the offset (left margin) for the chart content.
Uniform binning axis for histograms.
void init(int n, double min, double max)
Initialize the axis with uniform bins.
axis(int n, double min, double max)
Construct an axis with uniform bins.
int find(double value)
Find the bin index for a given value.
axis()
Default constructor.
Lightweight 1D histogram.
void fill(double value)
Fill the histogram with a value.
void series(std::vector< double > &data)
Extract bin contents (excluding under/overflow) into a vector.
static std::vector< h1d > declare(int count, int bins, double xmin, double xmax)
Create a vector of identical histograms.
static h1d accumulate(std::vector< h1d > &buffer)
Sum multiple histograms bin-by-bin.
void print()
Print an ASCII chart of the histogram to stdout.
void id(int __id)
Set the histogram ID.
h1d(int n, double min, double max)
Construct a histogram with uniform binning.
double content(int bin)
Get the content of a bin.
std::vector< double > container
void setContent(int bin, double value)
Set the content of a bin directly.
void show()
Print histogram contents as text columns to stdout.
h1d(int __id, int n, double min, double max)
Construct a histogram with an ID and uniform binning.