@@ -7,33 +7,38 @@ namespace plt = matplotlibcpp;
7
7
8
8
int main ()
9
9
{
10
- // Prepare data.
11
- int n = 5000 ;
12
- std::vector<double > x (n), y (n), z (n), w (n,2 );
13
- for (int i=0 ; i<n; ++i) {
14
- x.at (i) = i*i;
15
- y.at (i) = sin (2 *M_PI*i/360.0 );
16
- z.at (i) = log (i);
17
- }
10
+ // Prepare data.
11
+ int n = 5000 ;
12
+ std::vector<double > x (n), y (n), z (n), w (n,2 );
13
+ for (int i=0 ; i<n; ++i) {
14
+ x.at (i) = i*i;
15
+ y.at (i) = sin (2 *M_PI*i/360.0 );
16
+ z.at (i) = log (i);
17
+ }
18
18
19
19
// Set the size of output image = 1200x780 pixels
20
20
plt::figure_size (1200 , 780 );
21
+
21
22
// Plot line from given x and y data. Color is selected automatically.
22
23
plt::plot (x, y);
23
- // Plot a red dashed line from given x and y data.
24
- plt::plot (x, w," r--" );
25
- // Plot a line whose name will show up as "log(x)" in the legend.
26
- plt::named_plot (" log(x)" , x, z);
27
-
28
- // Set x-axis to interval [0,1000000]
29
- plt::xlim (0 , 1000 *1000 );
30
-
31
- // Add graph title
32
- plt::title (" Sample figure" );
33
- // Enable legend.
34
- plt::legend ();
35
- // save figure
36
- const char * filename = " ./basic.png" ;
37
- std::cout << " Saving result to " << filename << std::endl;;
38
- plt::save (filename);
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::named_plot (" log(x)" , x, z);
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
+ plt::save (filename);
39
44
}
0 commit comments