forked from lava/matplotlib-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodern.cpp
More file actions
37 lines (28 loc) · 1.27 KB
/
Copy pathmodern.cpp
File metadata and controls
37 lines (28 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#define _USE_MATH_DEFINES
#include <cmath>
#include "../matplotlibcpp.h"
using namespace std;
namespace plt = matplotlibcpp;
#include <xtensor/xbuilder.hpp>
#include <xtensor/xtensor.hpp>
#include <xtensor/xio.hpp>
int main()
{
// plot(y) - the x-coordinates are implicitly set to [0,1,...,n)
//plt::plot({1,2,3,4});
// Prepare data for parametric plot.
int n = 5000; // number of data points
xt::xtensor<double, 1> i = xt::linspace<double>(0, (n-1), n);
xt::xtensor<double, 1> t = 2 * xt::numeric_constants<double>::PI * i / n;
xt::xtensor<double, 1> x = 16*xt::sin(t)*xt::sin(t)*xt::sin(t);
xt::xtensor<double, 1> y = 13*xt::cos(t) - 5*xt::cos(2*t) - 2*xt::cos(3*t) - xt::cos(4*t);
xt::xtensor<double, 1> x2 = 16*xt::sin(t)*xt::sin(t)*xt::sin(t);
xt::xtensor<double, 1> y2 = 13*xt::cos(t) - 5*xt::cos(2*t) - 2*xt::cos(3*t) - xt::cos(4*t);
// plot() takes an arbitrary number of (x,y,format)-triples.
// x must be iterable (that is, anything providing begin(x) and end(x)),
// y must either be callable (providing operator() const) or iterable.
plt::plot(x, y, "r-", x, [](double d) { return 12.5+abs(sin(d)); }, "k-");
//plt::plot(x, y, "r-", x, [](double d) { return 12.5+abs(sin(d)); }, "k-", x, y+1.0, "r-.");
// show plots
plt::show();
}