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 | using namespace std; |
| 6 | namespace plt = matplotlibcpp; |
| 7 | |
| 8 | int main() |
| 9 | { |
| 10 | // plot(y) - the x-coordinates are implicitly set to [0,1,...,n) |
| 11 | //plt::plot({1,2,3,4}); |
| 12 | |
| 13 | // Prepare data for parametric plot. |
| 14 | int n = 5000; // number of data points |
| 15 | vector<double> x(n),y(n); |
| 16 | for(int i=0; i<n; ++i) { |
| 17 | double t = 2*M_PI*i/n; |
| 18 | x.at(i) = 16*sin(t)*sin(t)*sin(t); |
| 19 | y.at(i) = 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t); |
| 20 | } |
| 21 | |
| 22 | // plot() takes an arbitrary number of (x,y,format)-triples. |
| 23 | // x must be iterable (that is, anything providing begin(x) and end(x)), |
| 24 | // y must either be callable (providing operator() const) or iterable. |
| 25 | plt::plot(x, y, "r-", x, [](double d) { return 12.5+abs(sin(d)); }, "k-"); |
| 26 | |
| 27 | |
| 28 | // show plots |
| 29 | plt::show(); |
| 30 | } |