Subplots
Unlike other libraries, subplots uses 0-based indices.
More examples
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 | #include <iostream>
#include <matplot/matplot.h>
#include <set>
#include <thread>
#include <vector>
int main() {
using namespace matplot;
auto ax1 = subplot(2, 2, 0);
fplot("cos(x)");
title("Subplot 1: Cosine");
auto ax2 = subplot(2, 2, 1);
fplot("1 - x**2/2 + x**4/24");
title("Subplot 2: Polynomial");
auto ax3 = subplot(2, 2, {2, 3});
fplot("cos(x)", "b");
hold(on);
fplot("1 - x**2/2 + x**4/24", "g");
title("Subplot 3 and 4: Both");
axis({ax1, ax2, ax3}, {-4, 4, inf, inf});
show();
return 0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 | #include <matplot/matplot.h>
int main() {
using namespace matplot;
subplot({0.1f, 0.3f, 0.3f, 0.3f});
std::vector<std::vector<double>> y = {
{16, 5, 9, 4}, {2, 11, 7, 14}, {3, 10, 6, 15}, {13, 8, 12, 1}};
plot(y);
title("First Subplot");
subplot({0.5f, 0.15f, 0.4f, 0.7f});
bar(y);
title("Second Subplot");
show();
return 0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 | #include <matplot/matplot.h>
int main() {
using namespace matplot;
figure();
auto ax1 = subplot(2, 1, 0);
auto theta = linspace(0, 2 * pi, 50);
auto rho =
transform(theta, [](double theta) { return sin(theta) * cos(theta); });
polarplot(ax1, theta, rho);
auto ax2 = subplot(2, 1, 1);
polarscatter(ax2, theta, rho);
show();
return 0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | #include <matplot/matplot.h>
int main() {
using namespace matplot;
auto ax1 = subplot(2, 1, 0);
auto [x, y, z] = peaks();
(void) x;
(void) y;
z = transpose(z);
plot(ax1, z);
xlim(ax1, {0, 20});
auto ax2 = subplot(2, 1, 1);
plot(ax2, z);
ax1->font_size(15);
ax2->line_width(2);
show();
return 0;
}
|