blob: a8aa0c75db624839cfed965bb0520739b339191a [file] [log] [blame]
Austin Schuh6c8ec4c2018-01-23 11:18:57 -08001#define _USE_MATH_DEFINES
2#include <cmath>
3#include "../matplotlibcpp.h"
4
5using namespace std;
6namespace plt = matplotlibcpp;
7
8int 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}