Skip to content

Commit c7f73bb

Browse files
authoredMay 8, 2019
Merge pull request lava#2 from tkphd/imshow-example
Imshow example
2 parents 52931d5 + b8f0c00 commit c7f73bb

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed
 

‎Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
examples: minimal basic modern animation nonblock xkcd quiver bar surface fill_inbetween fill update
1+
examples: minimal basic modern animation nonblock xkcd quiver bar surface fill_inbetween fill update imshow
22

33
minimal: examples/minimal.cpp matplotlibcpp.h
44
cd examples && g++ -DWITHOUT_NUMPY minimal.cpp -I/usr/include/python2.7 -lpython2.7 -o minimal -std=c++11
@@ -32,9 +32,12 @@ fill_inbetween: examples/fill_inbetween.cpp matplotlibcpp.h
3232

3333
fill: examples/fill.cpp matplotlibcpp.h
3434
cd examples && g++ fill.cpp -I/usr/include/python2.7 -lpython2.7 -o fill -std=c++11
35-
35+
3636
update: examples/update.cpp matplotlibcpp.h
3737
cd examples && g++ update.cpp -I/usr/include/python2.7 -lpython2.7 -o update -std=c++11
3838

39+
imshow: examples/imshow.cpp matplotlibcpp.h
40+
cd examples && g++ imshow.cpp -I/usr/include/python2.7 -lpython2.7 -o imshow -std=c++11
41+
3942
clean:
40-
rm -f examples/{minimal,basic,modern,animation,nonblock,xkcd,quiver,bar,surface,fill_inbetween,fill,update}
43+
rm -f examples/{minimal,basic,modern,animation,nonblock,xkcd,quiver,bar,surface,fill_inbetween,fill,update,imshow}

‎examples/imshow.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#define _USE_MATH_DEFINES
2+
#include <cmath>
3+
#include "../matplotlibcpp.h"
4+
5+
using namespace std;
6+
namespace plt = matplotlibcpp;
7+
8+
int main()
9+
{
10+
// Prepare data
11+
int ncols = 500, nrows = 300;
12+
std::vector<float> z(ncols * nrows);
13+
for (int j=0; j<nrows; ++j) {
14+
for (int i=0; i<ncols; ++i) {
15+
z.at(ncols * j + i) = std::sin(std::hypot(i - ncols/2, j - nrows/2));
16+
}
17+
}
18+
19+
const float* zptr = &(z[0]);
20+
const int colors = 1;
21+
22+
plt::title("My matrix");
23+
plt::imshow(zptr, nrows, ncols, colors);
24+
25+
// Show plots
26+
plt::save("imshow.png");
27+
}

0 commit comments

Comments
 (0)
Please sign in to comment.