8000 Add a simple cmake example · lava/matplotlib-cpp@c4fb836 · GitHub
[go: up one dir, main page]

Skip to content

Commit c4fb836

Browse files
committed
Add a simple cmake example
1 parent 1d23b28 commit c4fb836

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
project(matplotlib_cpp)
2+
cmake_minimum_required(VERSION 3.1)
3+
set(CMAKE_CXX_STANDARD 14)
4+
set(PYTHON_LIBRARY /usr/lib/x86_64-linux-gnu/libpython2.7.so)
5+
set(PYTHON_INCLUDE_DIR /usr/include/python2.7)
6+
find_package(PythonLibs 2.7 REQUIRED)
7+
8+
include_directories(${PYTHON_INCLUDE_DIRS})
9+
10+
add_executable(modern modern.cpp matplotlibcpp.h)
11+
12+
message(${PYTHON_LIBRARIES})
13+
target_link_libraries(
14+
modern
15+
${PYTHON_LIBRARIES}
16+
)

modern.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <cmath>
2+
#include "matplotlibcpp.h"
3+
4+
using namespace std;
5+
namespace plt = matplotlibcpp;
6+
7+
int main()
8+
{
9+
// Prepare data.
10+
int n = 5000; // number of data points
11+
vector<double> x(n),y(n);
12+
for(int i=0; i<n; ++i) {
13+
double t = 2*M_PI*i/n;
14+
x.at(i) = 16*sin(t)*sin(t)*sin(t);
15+
y.at(i) = 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t);
16+
}
17+
18+
// plot() takes an arbitrary number of (x,y,format)-triples.
19+
// x must be iterable (that is, anything providing begin(x) and end(x)),
20+
// y must either be callable (providing operator() const) or iterable.
21+
plt::plot(x, y, "r-", x, [](double d) { return 12.5+abs(sin(d)); }, "k-");
22+
23+
24+
// show plots
25+
plt::show();
26+
}

0 commit comments

Comments
 (0)
0