8000 Added basic example for imshow. · sadads1337/matplotlib-cpp@bc7e457 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc7e457

Browse files
tkphdBenno Evers
authored and
Benno Evers
committed
Added basic example for imshow.
This addresses comments on lava#79.
1 parent 20e090e commit bc7e457

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
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

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

0 commit comments

Comments
 (0)
0