trase
Animated Histogram Geometry

This is an example for the histogram geometry

example_histogram.svg
Output
#include "trase.hpp"
#include <fstream>
#include <random>
using namespace trase;
int main() {
auto fig = figure();
auto ax = fig->axis();
const int n = 100;
std::vector<float> x(n);
std::default_random_engine gen;
std::normal_distribution<float> normal(0, 1);
std::generate(x.begin(), x.end(), [&]() { return normal(gen); });
auto data = create_data().x(x);
auto hist = ax->histogram(data);
hist->set_label("hist");
float time = 0.0;
auto do_plot = [&](const float theta) {
time += 0.3f;
std::normal_distribution<float> normal(theta, 1);
std::generate(x.begin(), x.end(), [&]() { return normal(gen); });
auto data = create_data().x(x);
hist->add_frame(data, time);
};
for (int i = 0; i < 5; ++i) {
const float theta = i / 5.f;
do_plot(theta);
}
ax->xlabel("x");
ax->ylabel("y");
ax->title("histogram test");
ax->legend();
// output to chosen backend
#ifdef TRASE_EXAMPLES_SVG_BACKEND
std::ofstream out;
out.open("example_histogram.svg");
BackendSVG backend(out);
fig->draw(backend);
out.close();
#endif
#ifdef TRASE_EXAMPLES_GL_BACKEND
BackendGL backend;
fig->show(backend);
#endif
}