From 0533f6b66324610c3a799c0b7020b99b67b334ef Mon Sep 17 00:00:00 2001 From: HenryFuhengWu Date: Sun, 25 Aug 2019 11:26:45 -0700 Subject: [PATCH 1/2] make -f Makefile.Python3 --- Makefile.Python3 | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Makefile.Python3 diff --git a/Makefile.Python3 b/Makefile.Python3 new file mode 100644 index 0000000..3b588cc --- /dev/null +++ b/Makefile.Python3 @@ -0,0 +1,43 @@ +examples: minimal basic modern animation nonblock xkcd quiver bar surface fill_inbetween fill update imshow + +minimal: examples/minimal.cpp matplotlibcpp.h + cd examples && g++ -DWITHOUT_NUMPY minimal.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o minimal -std=c++17 + +basic: examples/basic.cpp matplotlibcpp.h + cd examples && g++ basic.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o basic -std=c++17 + +modern: examples/modern.cpp matplotlibcpp.h + cd examples && g++ modern.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o modern -std=c++17 + +animation: examples/animation.cpp matplotlibcpp.h + cd examples && g++ animation.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o animation -std=c++17 + +nonblock: examples/nonblock.cpp matplotlibcpp.h + cd examples && g++ nonblock.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o nonblock -std=c++17 + +quiver: examples/quiver.cpp matplotlibcpp.h + cd examples && g++ quiver.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o quiver -std=c++17 + +xkcd: examples/xkcd.cpp matplotlibcpp.h + cd examples && g++ xkcd.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o xkcd -std=c++17 + +bar: examples/bar.cpp matplotlibcpp.h + cd examples && g++ bar.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o bar -std=c++17 + +surface: examples/surface.cpp matplotlibcpp.h + cd examples && g++ surface.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o surface -std=c++17 + +fill_inbetween: examples/fill_inbetween.cpp matplotlibcpp.h + cd examples && g++ fill_inbetween.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o fill_inbetween -std=c++17 + +fill: examples/fill.cpp matplotlibcpp.h + cd examples && g++ fill.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o fill -std=c++17 + +update: examples/update.cpp matplotlibcpp.h + cd examples && g++ update.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o update -std=c++17 + +imshow: examples/imshow.cpp matplotlibcpp.h + cd examples && g++ imshow.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o imshow -std=c++17 + +clean: + rm -f examples/{minimal,basic,modern,animation,nonblock,xkcd,quiver,bar,surface,fill_inbetween,fill,update,imshow} From 6a20420775a7896eb49a7d1f2afe4666881850df Mon Sep 17 00:00:00 2001 From: HenryFuhengWu Date: Sun, 25 Aug 2019 17:17:47 -0700 Subject: [PATCH 2/2] bug fix --- Makefile.Python3 | 28 +++++++++++++++------------- examples/basic.cpp | 1 + examples/imshow.cpp | 1 + examples/minimal.cpp | 1 + examples/modern.cpp | 1 + examples/nonblock.cpp | 1 + examples/update.cpp | 1 + matplotlibcpp.h | 2 +- 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Makefile.Python3 b/Makefile.Python3 index 3b588cc..003b6d2 100644 --- a/Makefile.Python3 +++ b/Makefile.Python3 @@ -1,43 +1,45 @@ examples: minimal basic modern animation nonblock xkcd quiver bar surface fill_inbetween fill update imshow +CPPFLAGS = -g -O0 -DSF_VISIBILITY -fvisibility=hidden -fno-strict-aliasing -Wall + minimal: examples/minimal.cpp matplotlibcpp.h - cd examples && g++ -DWITHOUT_NUMPY minimal.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o minimal -std=c++17 + cd examples && g++ $(CPPFLAGS) -DWITHOUT_NUMPY minimal.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o minimal -std=c++17 basic: examples/basic.cpp matplotlibcpp.h - cd examples && g++ basic.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o basic -std=c++17 + cd examples && g++ $(CPPFLAGS) basic.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o basic -std=c++17 modern: examples/modern.cpp matplotlibcpp.h - cd examples && g++ modern.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o modern -std=c++17 + cd examples && g++ $(CPPFLAGS) modern.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o modern -std=c++17 animation: examples/animation.cpp matplotlibcpp.h - cd examples && g++ animation.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o animation -std=c++17 + cd examples && g++ $(CPPFLAGS) animation.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o animation -std=c++17 nonblock: examples/nonblock.cpp matplotlibcpp.h - cd examples && g++ nonblock.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o nonblock -std=c++17 + cd examples && g++ $(CPPFLAGS) nonblock.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o nonblock -std=c++17 quiver: examples/quiver.cpp matplotlibcpp.h - cd examples && g++ quiver.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o quiver -std=c++17 + cd examples && g++ $(CPPFLAGS) quiver.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o quiver -std=c++17 xkcd: examples/xkcd.cpp matplotlibcpp.h - cd examples && g++ xkcd.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o xkcd -std=c++17 + cd examples && g++ $(CPPFLAGS) xkcd.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o xkcd -std=c++17 bar: examples/bar.cpp matplotlibcpp.h - cd examples && g++ bar.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o bar -std=c++17 + cd examples && g++ $(CPPFLAGS) bar.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o bar -std=c++17 surface: examples/surface.cpp matplotlibcpp.h - cd examples && g++ surface.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o surface -std=c++17 + cd examples && g++ $(CPPFLAGS) surface.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o surface -std=c++17 fill_inbetween: examples/fill_inbetween.cpp matplotlibcpp.h - cd examples && g++ fill_inbetween.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o fill_inbetween -std=c++17 + cd examples && g++ $(CPPFLAGS) fill_inbetween.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o fill_inbetween -std=c++17 fill: examples/fill.cpp matplotlibcpp.h - cd examples && g++ fill.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o fill -std=c++17 + cd examples && g++ $(CPPFLAGS) fill.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o fill -std=c++17 update: examples/update.cpp matplotlibcpp.h - cd examples && g++ update.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o update -std=c++17 + cd examples && g++ update.cpp $(CPPFLAGS) -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o update -std=c++1z imshow: examples/imshow.cpp matplotlibcpp.h - cd examples && g++ imshow.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o imshow -std=c++17 + cd examples && g++ $(CPPFLAGS) imshow.cpp -Iext/plot/ $(shell python3-config --includes) $(shell python3-config --ldflags) -lopencv_core -lopencv_imgproc -o imshow -std=c++17 clean: rm -f examples/{minimal,basic,modern,animation,nonblock,xkcd,quiver,bar,surface,fill_inbetween,fill,update,imshow} diff --git a/examples/basic.cpp b/examples/basic.cpp index 2dc34c7..ac7b827 100644 --- a/examples/basic.cpp +++ b/examples/basic.cpp @@ -7,6 +7,7 @@ namespace plt = matplotlibcpp; int main() { + plt::detail::_interpreter::get(); // Prepare data. int n = 5000; std::vector x(n), y(n), z(n), w(n,2); diff --git a/examples/imshow.cpp b/examples/imshow.cpp index b11661e..578b5f6 100644 --- a/examples/imshow.cpp +++ b/examples/imshow.cpp @@ -8,6 +8,7 @@ namespace plt = matplotlibcpp; int main() { + plt::detail::_interpreter::get(); // Prepare data int ncols = 500, nrows = 300; std::vector z(ncols * nrows); diff --git a/examples/minimal.cpp b/examples/minimal.cpp index fbe1e1c..91159c2 100644 --- a/examples/minimal.cpp +++ b/examples/minimal.cpp @@ -3,6 +3,7 @@ namespace plt = matplotlibcpp; int main() { + plt::detail::_interpreter::get(); plt::plot({1,3,2,4}); plt::show(); } diff --git a/examples/modern.cpp b/examples/modern.cpp index a8aa0c7..e764d7e 100644 --- a/examples/modern.cpp +++ b/examples/modern.cpp @@ -7,6 +7,7 @@ namespace plt = matplotlibcpp; int main() { + plt::detail::_interpreter::get(); // plot(y) - the x-coordinates are implicitly set to [0,1,...,n) //plt::plot({1,2,3,4}); diff --git a/examples/nonblock.cpp b/examples/nonblock.cpp index 327d96c..1d2cc59 100644 --- a/examples/nonblock.cpp +++ b/examples/nonblock.cpp @@ -10,6 +10,7 @@ using namespace std; int main() { + plt::detail::_interpreter::get(); // Prepare data. int n = 5000; std::vector x(n), y(n), z(n), w(n,2); diff --git a/examples/update.cpp b/examples/update.cpp index 64f4906..4007eb8 100644 --- a/examples/update.cpp +++ b/examples/update.cpp @@ -20,6 +20,7 @@ void update_window(const double x, const double y, const double t, int main() { + plt::detail::_interpreter::get(); size_t n = 1000; std::vector x, y; diff --git a/matplotlibcpp.h b/matplotlibcpp.h index 6a428d4..8cdd7d1 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -1701,7 +1701,7 @@ struct plot_impl PyObject* pystring = PyString_FromString(format.c_str()); auto itx = begin(x), ity = begin(y); - for(size_t i = 0; i < xs; ++i) { + for(auto i = 0; i < xs; ++i) { PyList_SetItem(xlist, i, PyFloat_FromDouble(*itx++)); PyList_SetItem(ylist, i, PyFloat_FromDouble(*ity++)); }