File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ #define _USE_MATH_DEFINES
2+ #include " ../../matplotlibcpp.h"
3+ #include < Eigen/Dense>
4+ #include < cmath>
5+ #include < iostream>
6+
7+ namespace plt = matplotlibcpp;
8+
9+ int main () {
10+ // Prepare data.
11+ int n = 5000 ;
12+ Eigen::VectorXd x (n), y (n), z (n), w = 2 * Eigen::VectorXd::Ones (n);
13+ for (int i = 0 ; i < n; ++i) {
14+ x (i) = i * i;
15+ y (i) = sin (2 * M_PI * i / 360.0 );
16+ z (i) = log (i);
17+ }
18+
19+ // Set the size of output image = 1200x780 pixels
20+ plt::figure_size (1200 , 780 );
21+
22+ // Plot line from given x and y data. Color is selected automatically.
23+ plt::plot (x, y);
24+
25+ // Plot a red dashed line from given x and y data.
26+ plt::plot (x, w, " r--" );
27+
28+ // Plot a line whose name will show up as "log(x)" in the legend.
29+ plt::plot (x, z, {{" label" , " log(x)" }});
30+
31+ // Set x-axis to interval [0,1000000]
32+ plt::xlim (0 , 1000 * 1000 );
33+
34+ // Add graph title
35+ plt::title (" Sample figure" );
36+
37+ // Enable legend.
38+ plt::legend ();
39+
40+ // save figure
41+ const char *filename = " ./basic.png" ;
42+ std::cout << " Saving result to " << filename << std::endl;
43+
44+ plt::save (filename);
45+ }
You can’t perform that action at this time.
0 commit comments