Pārlūkot izejas kodu

Add picture and cpp file for new surface example.

Benno Evers 6 gadi atpakaļ
vecāks
revīzija
eae3824b07
4 mainītis faili ar 33 papildinājumiem un 2 dzēšanām
  1. 4 1
      Makefile
  2. 5 1
      README.md
  3. 24 0
      examples/surface.cpp
  4. BIN
      examples/surface.png

+ 4 - 1
Makefile

@@ -1,4 +1,4 @@
-examples: minimal basic modern animation nonblock xkcd quiver bar
+examples: minimal basic modern animation nonblock xkcd quiver bar surface
 
 minimal: examples/minimal.cpp matplotlibcpp.h
 	cd examples && g++ -DWITHOUT_NUMPY minimal.cpp -I/usr/include/python2.7 -lpython2.7 -o minimal -std=c++11
@@ -24,5 +24,8 @@ xkcd: examples/xkcd.cpp matplotlibcpp.h
 bar: examples/bar.cpp matplotlibcpp.h
 	cd examples && g++ bar.cpp -I/usr/include/python2.7 -lpython2.7 -o bar -std=c++11
 
+surface: examples/surface.cpp matplotlibcpp.h
+	cd examples && g++ surface.cpp -I/usr/include/python2.7 -lpython2.7 -o surface -std=c++11
+
 clean:
 	rm -f examples/{minimal,basic,modern,animation,nonblock,xkcd,quiver,bar}

+ 5 - 1
README.md

@@ -173,7 +173,7 @@ int main()
         for (double j = -5; j <= 5; j += 0.25) {
             x_row.push_back(i);
             y_row.push_back(j);
-            z_row.push_back(::std::sin(::std::hypot(x, y)));
+            z_row.push_back(::std::sin(::std::hypot(i, j)));
         }
         x.push_back(x_row);
         y.push_back(y_row);
@@ -185,6 +185,10 @@ int main()
 }
 ```
 
+**Result:**
+
+![surface example](./examples/surface.png)
+
 Installation
 ------------
 

+ 24 - 0
examples/surface.cpp

@@ -0,0 +1,24 @@
+#include "../matplotlibcpp.h"
+
+#include <cmath>
+
+namespace plt = matplotlibcpp;
+
+int main()
+{
+    std::vector<std::vector<double>> x, y, z;
+    for (double i = -5; i <= 5;  i += 0.25) {
+        std::vector<double> x_row, y_row, z_row;
+        for (double j = -5; j <= 5; j += 0.25) {
+            x_row.push_back(i);
+            y_row.push_back(j);
+            z_row.push_back(::std::sin(::std::hypot(i, j)));
+        }
+        x.push_back(x_row);
+        y.push_back(y_row);
+        z.push_back(z_row);
+    }
+
+    plt::plot_surface(x, y, z);
+    plt::show();
+}

BIN
examples/surface.png