Austin Schuh | ab802d5 | 2020-07-03 18:11:11 -0700 | [diff] [blame] | 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 | } |