forked from lava/matplotlib-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolorbar.cpp
More file actions
32 lines (27 loc) · 689 Bytes
/
colorbar.cpp
File metadata and controls
32 lines (27 loc) · 689 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
30
31
32
#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");
PyObject* mat;
plt::imshow(zptr, nrows, ncols, colors, {}, &mat);
plt::colorbar(mat);
// Show plots
plt::show();
plt::close();
Py_DECREF(mat);
}