Austin Schuh | 6c8ec4c | 2018-01-23 11:18:57 -0800 | [diff] [blame^] | 1 | #define _USE_MATH_DEFINES |
| 2 | #include <cmath> |
| 3 | #include "../matplotlibcpp.h" |
| 4 | |
| 5 | namespace plt = matplotlibcpp; |
| 6 | |
| 7 | |
| 8 | using namespace matplotlibcpp; |
| 9 | using namespace std; |
| 10 | |
| 11 | int main() |
| 12 | { |
| 13 | // Prepare data. |
| 14 | int n = 5000; |
| 15 | std::vector<double> x(n), y(n), z(n), w(n,2); |
| 16 | for(int i=0; i<n; ++i) { |
| 17 | x.at(i) = i*i; |
| 18 | y.at(i) = sin(2*M_PI*i/360.0); |
| 19 | z.at(i) = log(i); |
| 20 | } |
| 21 | |
| 22 | // Plot line from given x and y data. Color is selected automatically. |
| 23 | plt::subplot(2,2,1); |
| 24 | plt::plot(x, y); |
| 25 | |
| 26 | // Plot a red dashed line from given x and y data. |
| 27 | plt::subplot(2,2,2); |
| 28 | plt::plot(x, w,"r--"); |
| 29 | |
| 30 | // Plot a line whose name will show up as "log(x)" in the legend. |
| 31 | plt::subplot(2,2,3); |
| 32 | plt::named_plot("log(x)", x, z); |
| 33 | |
| 34 | // Set x-axis to interval [0,1000000] |
| 35 | plt::xlim(0, 1000*1000); |
| 36 | |
| 37 | // Add graph title |
| 38 | plt::title("Sample figure"); |
| 39 | // Enable legend. |
| 40 | plt::legend(); |
| 41 | |
| 42 | plt::show(false); |
| 43 | |
| 44 | cout << "matplotlibcpp::show() is working in an non-blocking mode" << endl; |
| 45 | getchar(); |
| 46 | } |