Related projects
xplot if the C++ backend for the bqplot 2-D plotting library
C++ code
#include <algorithm>
#include <random>
#include <vector>
#include "xwidgets/xbox.hpp"
#include "xplot/xtoolbar.hpp"
#include "xplot/xfigure.hpp"
#include "xplot/xmarks.hpp"
#include "xplot/xaxes.hpp"
auto randn(std::size_t n)
{
std::vector<double> output(n);
std::random_device rd;
std::mt19937 gen(rd());
std::normal_distribution<> dis(5, 2);
std::for_each(output.begin(), output.end(), [&dis, &gen](auto& v){v = dis(gen);});
return output;
}
std::size_t data_size = 200;
std::vector<double> data_x(data_size);
std::iota(data_x.begin(), data_x.end(), 0);
std::vector<double> data_y = randn(data_size);
std::vector<double> data_c = randn(data_size);
xpl::linear_scale scale_x, scale_y;
xpl::linear_scale scale_size;
auto scatter = xpl::scatter::initialize(scale_x, scale_y, scale_size);
scatter.x = data_x;
scatter.y = data_y;
scatter.size = data_c;
scatter.stroke = "black";
scatter.default_size = 128;
scatter.enable_move = true;
scatter.colors = std::vector<xtl::xoptional<std::string>>{"orangered"};
scatter.finalize();
xpl::axis axis_x(scale_x), axis_y(scale_y);
axis_x.label = "x";
axis_y.label = "y";
axis_y.orientation = "vertical";
axis_y.side = "left";
xpl::figure fig;
fig.padding_x = 0.025;
fig.add_mark(scatter);
fig.add_axis(axis_x);
fig.add_axis(axis_y);
xpl::toolbar tb(fig);
xw::vbox b = xw::vbox::initialize();
b.children = {fig, tb};
b.finalize();
b
Output
xleaflet is the C++ backend for the leaflet maps visualization library. The Python reference implementation is available in the ipyleaflet project
C++ code
#include "xwidgets/xhtml.hpp"
#include "xleaflet/xmap.hpp"
#include "xleaflet/xmarker.hpp"
auto html = xw::html::initialize();
html.value = "Hello from an <b>xwidget</b> in an <b>xmarker</b>!";
html.finalize();
std::array<double, 2> center = {52.204793, 360.121558};
auto map = xlf::map::initialize();
map.center = center;
map.zoom = 15;
map.finalize();
auto marker = xlf::marker::initialize();
marker.location = center;
marker.draggable = false;
marker.popup = html;
marker.finalize();
map.add_layer(marker);
map
Output
xproperty is the C++ implementation of the observer pattern underlying
xwidgets. It is to xwidgets what the traitlets project is to
ipywidgets.