|
| 1 | +// |
| 2 | +// g++ -g -Wall -o modern $(python-config --includes --cflags) modern.cpp $(python-config --ldflags --embed) |
| 3 | +// |
| 4 | + |
1 | 5 | #define _USE_MATH_DEFINES
|
2 | 6 | #include <cmath>
|
3 | 7 | #include "../matplotlibcpp.h"
|
4 | 8 |
|
5 | 9 | using namespace std;
|
6 | 10 | namespace plt = matplotlibcpp;
|
7 | 11 |
|
8 |
| -int main() |
| 12 | +int main() |
9 | 13 | {
|
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 |
| - //plt::set_aspect(0.5); |
28 |
| - plt::set_aspect_equal(); |
29 |
| - |
30 |
| - |
31 |
| - // show plots |
32 |
| - plt::show(); |
| 14 | + // plot(y) - the x-coordinates are implicitly set to [0,1,...,n) |
| 15 | + //plt::plot({1,2,3,4}); |
| 16 | + |
| 17 | + // Prepare data for parametric plot. |
| 18 | + int n = 5000; // number of data points |
| 19 | + vector<double> x(n),y(n); |
| 20 | + for(int i=0; i<n; ++i) { |
| 21 | + double t = 2*M_PI*i/n; |
| 22 | + x.at(i) = 16*sin(t)*sin(t)*sin(t); |
| 23 | + y.at(i) = 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t); |
| 24 | + } |
| 25 | + |
| 26 | + // plot() takes an arbitrary number of (x,y,format)-triples. |
| 27 | + // x must be iterable (that is, anything providing begin(x) and end(x)), |
| 28 | + // y must either be callable (providing operator() const) or iterable. |
| 29 | + plt::plot(x, y, "r-", x, [](double d) { return 12.5+abs(sin(d)); }, "k-"); |
| 30 | + |
| 31 | + //plt::set_aspect(0.5); |
| 32 | + plt::set_aspect_equal(); |
| 33 | + |
| 34 | + |
| 35 | + // show plots |
| 36 | + plt::show(); |
| 37 | + |
| 38 | + plt::detail::_interpreter::kill(); |
| 39 | + return 0; |
33 | 40 | }
|
0 commit comments