blob: b11661e412d96de823f4bd8fe05d36d96ece4978 [file] [log] [blame]
Austin Schuhab802d52020-07-03 18:11:11 -07001#define _USE_MATH_DEFINES
2#include <cmath>
3#include <iostream>
4#include "../matplotlibcpp.h"
5
6using namespace std;
7namespace plt = matplotlibcpp;
8
9int 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}