forked from lava/matplotlib-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimshow.cpp
More file actions
29 lines (24 loc) · 662 Bytes
/
imshow.cpp
File metadata and controls
29 lines (24 loc) · 662 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include "../matplotlibcpp.h"
using namespace std;
namespace plt = matplotlibcpp;
int main()
{
// Prepare data
int ncols = 500, nrows = 300;
std::vector<float> z(ncols * nrows);
for (int j=0; j<nrows; ++j) {
for (int i=0; i<ncols; ++i) {
z.at(ncols * j + i) = std::sin(std::hypot(i - ncols/2, j - nrows/2));
}
}
const float* zptr = &(z[0]);
const int colors = 1;
plt::title("My matrix");
plt::imshow(zptr, nrows, ncols, colors);
// Show plots
plt::save("imshow.png");
std::cout << "Result saved to 'imshow.png'.\n";
}