1
+ #include " ../../include/cppyplot.hpp"
2
+
3
+ #include < vector>
4
+ #include < random>
5
+ #include < numeric>
6
+
7
+ #include < Eigen/Eigen/Core>
8
+
9
+ /*
10
+ * Uncomment seaborn imports in cppyplot_server.py for this example to work
11
+ */
12
+
13
+ int main ()
14
+ {
15
+ Eigen::Matrix<double , 1000 , 1 > mat;
16
+ mat.setRandom ();
17
+
18
+ Cppyplot::cppyplot pyp;
19
+
20
+ pyp.raw (R"pyp(
21
+ fig = plt.figure(figsize=(6,5))
22
+ ax = sns.distplot(mat, kde=False,
23
+ hist_kws={"histtype": "bar", "rwidth": 3,
24
+ "alpha": 0.6, "color": "b"})
25
+ sns.distplot(mat, kde=False,
26
+ hist_kws={"histtype": "step", "rwidth": 2,
27
+ "alpha": 0.9, "color": "orange"})
28
+ ax.set_xlabel("Data bins", fontsize=12)
29
+ ax.set_ylabel("Frequency", fontsize=12)
30
+ ax.set_title("Histogram of C++ Eigen container", fontsize=14)
31
+ plt.show()
32
+ )pyp" );
33
+ pyp.data_args (_p (mat));
34
+
35
+ // bivariate plot from https://seaborn.pydata.org/examples/layered_bivariate_plot.html
36
+
37
+ std::vector<std::vector<double >> rand_mat (1000 , std::vector<double >(2 ));
38
+ std::random_device seed;
39
+ std::mt19937 gen (seed ());
40
+ std::normal_distribution<double > norm (0.0 , 10.0 );
41
+
42
+ // fill matrix
43
+ for (auto & row: rand_mat)
44
+ {
45
+ for (auto & elem: row)
46
+ { elem = norm (gen); }
47
+ }
48
+
49
+ pyp.raw (R"pyp(
50
+ sns.set_theme(style="dark")
51
+ f, ax = plt.subplots(figsize=(6,6))
52
+ sns.scatterplot(x=rand_mat[:,0], y=rand_mat[:,1], s=5, color="0.15")
53
+ sns.histplot(x=rand_mat[:,0], y=rand_mat[:,1], bins=50, pthresh=0.1, cmap="mako")
54
+ sns.kdeplot(x=rand_mat[:,0], y=rand_mat[:,1], levels=5, color="w", linewidths=1)
55
+ plt.show()
56
+ )pyp" );
57
+
58
+ pyp.data_args (_p (rand_mat));
59
+
60
+ return EXIT_SUCCESS;
61
+ }
0 commit comments