diff --git a/.gitignore b/.gitignore index 7622be7..06ba058 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,10 @@ # Build /examples/build/* + +.idea +/ref +/urdfdom_build +/cmake-build* +/*build* +/untrack \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..07cfbda --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.12) +project(matplotlibcpp-example) +set(CMAKE_CXX_STANDARD 14) +add_subdirectory(./examples) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..4f0acc2 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,40 @@ +if (EXISTS /opt/anaconda3) + set(PYTHON_INCLUDE_DIR /opt/anaconda3/include/python3.6m) + set(PYTHON_LIBRARIES /opt/anaconda3/lib/libpython3.6m.so) +else () + find_package(PythonLibs) + if (NOT PYTHONLIBS_FOUND) + message(FATAL_ERROR "PYTHONLIBS not found") + endif () +endif () +include_directories(${PYTHON_INCLUDE_DIR}) +add_executable(bar bar.cpp) +target_link_libraries(bar ${PYTHON_LIBRARIES}) +add_executable(animation animation.cpp) +target_link_libraries(animation ${PYTHON_LIBRARIES}) +add_executable(basic basic.cpp) +target_link_libraries(basic ${PYTHON_LIBRARIES}) +add_executable(fill fill.cpp) +target_link_libraries(fill ${PYTHON_LIBRARIES}) +add_executable(fill_inbetween fill_inbetween.cpp) +target_link_libraries(fill_inbetween ${PYTHON_LIBRARIES}) +add_executable(imshow imshow.cpp) +target_link_libraries(imshow ${PYTHON_LIBRARIES}) +add_executable(minimal minimal.cpp) +target_link_libraries(minimal ${PYTHON_LIBRARIES}) +add_executable(modern modern.cpp) +target_link_libraries(modern ${PYTHON_LIBRARIES}) +add_executable(nonblock nonblock.cpp) +target_link_libraries(nonblock ${PYTHON_LIBRARIES}) +add_executable(quiver quiver.cpp) +target_link_libraries(quiver ${PYTHON_LIBRARIES}) +add_executable(subplot subplot.cpp) +target_link_libraries(subplot ${PYTHON_LIBRARIES}) +add_executable(subplot2grid subplot2grid.cpp) +target_link_libraries(subplot2grid ${PYTHON_LIBRARIES}) +add_executable(surface surface.cpp) +target_link_libraries(surface ${PYTHON_LIBRARIES}) +add_executable(update update.cpp) +target_link_libraries(update ${PYTHON_LIBRARIES}) +add_executable(xkcd xkcd.cpp) +target_link_libraries(xkcd ${PYTHON_LIBRARIES}) \ No newline at end of file diff --git a/examples/bar.png b/examples/bar.png deleted file mode 100644 index be6af0f..0000000 Binary files a/examples/bar.png and /dev/null differ diff --git a/examples/basic.cpp b/examples/basic.cpp index 2dc34c7..0f61e3c 100644 --- a/examples/basic.cpp +++ b/examples/basic.cpp @@ -1,21 +1,21 @@ #define _USE_MATH_DEFINES + #include #include #include "../matplotlibcpp.h" namespace plt = matplotlibcpp; -int main() -{ +int main() { // Prepare data. int n = 5000; - std::vector x(n), y(n), z(n), w(n,2); - for(int i=0; i x(n), y(n), z(n), w(n, 2); + for (int i = 0; i < n; ++i) { + x.at(i) = i * i; + y.at(i) = sin(2 * M_PI * i / 360.0); z.at(i) = log(i); } - + // Set the size of output image = 1200x780 pixels plt::figure_size(1200, 780); @@ -23,13 +23,13 @@ int main() plt::plot(x, y); // Plot a red dashed line from given x and y data. - plt::plot(x, w,"r--"); + plt::plot(x, w, "r--"); // Plot a line whose name will show up as "log(x)" in the legend. plt::named_plot("log(x)", x, z); // Set x-axis to interval [0,1000000] - plt::xlim(0, 1000*1000); + plt::xlim(0, 1000 * 1000); // Add graph title plt::title("Sample figure"); @@ -38,7 +38,7 @@ int main() plt::legend(); // save figure - const char* filename = "./basic.png"; + const char *filename = "./basic.png"; std::cout << "Saving result to " << filename << std::endl;; plt::save(filename); } diff --git a/examples/basic.png b/examples/basic.png deleted file mode 100644 index 4d87ff0..0000000 Binary files a/examples/basic.png and /dev/null differ diff --git a/examples/fill.png b/examples/fill.png deleted file mode 100644 index aa1fc0d..0000000 Binary files a/examples/fill.png and /dev/null differ diff --git a/examples/fill_between.png b/examples/fill_between.png deleted file mode 100644 index a199423..0000000 Binary files a/examples/fill_between.png and /dev/null differ diff --git a/examples/minimal.png b/examples/minimal.png deleted file mode 100644 index 0f6cf37..0000000 Binary files a/examples/minimal.png and /dev/null differ diff --git a/examples/modern.png b/examples/modern.png deleted file mode 100644 index 0c51555..0000000 Binary files a/examples/modern.png and /dev/null differ diff --git a/examples/quiver.png b/examples/quiver.png deleted file mode 100644 index 9d7be1e..0000000 Binary files a/examples/quiver.png and /dev/null differ diff --git a/examples/surface.png b/examples/surface.png deleted file mode 100644 index 6fc5fc7..0000000 Binary files a/examples/surface.png and /dev/null differ diff --git a/examples/xkcd.png b/examples/xkcd.png deleted file mode 100644 index c285e3d..0000000 Binary files a/examples/xkcd.png and /dev/null differ