blob: 2b02f27b64f823a6e89e38e24127f08dcdba2387 [file] [log] [blame]
Austin Schuh6c8ec4c2018-01-23 11:18:57 -08001#define _USE_MATH_DEFINES
2#include <iostream>
3#include <cmath>
4#include "../matplotlibcpp.h"
5
6namespace plt = matplotlibcpp;
7
8int main()
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 }
18
19 // Plot line from given x and y data. Color is selected automatically.
20 plt::plot(x, y);
21 // Plot a red dashed line from given x and y data.
22 plt::plot(x, w,"r--");
23 // Plot a line whose name will show up as "log(x)" in the legend.
24 plt::named_plot("log(x)", x, z);
25
26 // Set x-axis to interval [0,1000000]
27 plt::xlim(0, 1000*1000);
28
29 // Add graph title
30 plt::title("Sample figure");
31 // Enable legend.
32 plt::legend();
33 // save figure
34 const char* filename = "./basic.png";
35 std::cout << "Saving result to " << filename << std::endl;;
36 plt::save(filename);
37}