In [ ]:
#include <vector>
#include <string>
#include "xtensor/xtensor.hpp"
#include "xtensor/xrandom.hpp"
#include "xtensor/xeval.hpp"
#include "xtensor/xmath.hpp"
#include "xwidgets/xslider.hpp"
#include "xwidgets/xlink.hpp"
#include "xplot/xfigure.hpp"
#include "xplot/xmarks.hpp"
#include "xplot/xaxes.hpp"
In [ ]:
std::size_t n = 200;
auto x = xt::linspace(0.0, 10.0, n);
xt::random::seed(0);
auto cumsum = xt::eval(xt::cumsum(xt::random::randn<double>({n})));
auto y = xt::eval(xt::floor(cumsum * 10.0));
auto fig = xpl::figure_generator().title("Histogram").finalize();
xpl::linear_scale xs, ys;
xpl::hist hist(xs, ys);
hist.sample = y;
hist.bins = 25;
hist.colors = std::vector<std::string>({"#1f77b4"});
xpl::axis hx(xs), hy(ys);
hy.orientation = "vertical";
fig.add_axis(hx);
fig.add_axis(hy);
fig.add_mark(hist);
fig
In [ ]:
auto slider = xw::slider_generator<std::size_t>()
.min(1).max(100)
.value(30).finalize();
auto l = xw::link(slider, "value", hist, "bins");
slider
In [ ]: