This example demonstrates how to create multiple subplots in a 2x2 grid layout, showing different sine wave phases in each subplot.
#include <cmath>
#include <vector>
auto main(
int argc,
char *argv[]) ->
int {
std::vector<double> x;
for (double t = 0; t < 4 * M_PI; t += 0.1) {
x.push_back(t);
}
std::vector<double> y1, y2, y3, y4;
for (double t : x) {
y1.push_back(std::sin(t));
y2.push_back(std::sin(t + M_PI / 4));
y3.push_back(std::sin(t + M_PI / 2));
y4.push_back(std::sin(t + 3 * M_PI / 4));
}
{"y", y1},
{"type", "scatter"},
{"mode", "lines"},
{"name", "sin(t)"}};
{"y", y2},
{"xaxis", "x2"},
{"yaxis", "y2"},
{"type", "scatter"},
{"mode", "lines"},
{"name", "sin(t + π/4)"}};
{"y", y3},
{"xaxis", "x3"},
{"yaxis", "y3"},
{"type", "scatter"},
{"mode", "lines"},
{"name", "sin(t + π/2)"}};
{"y", y4},
{"xaxis", "x4"},
{"yaxis", "y4"},
{"type", "scatter"},
{"mode", "lines"},
{"name", "sin(t + 3π/4)"}};
{"title", {{"text", "2x2 Subplot Grid - Phase-shifted Sine Waves"}}},
{"grid", {{"rows", 2}, {"columns", 2}, {"pattern", "independent"}}},
{"showlegend", false}};
if (!args.headless) {
} else {
{"width", 800},
{"height", 600},
{"filename", "2x2_subplots"}};
}
return 0;
}
auto parseGalleryArgs(int argc, char *argv[]) -> GalleryArgs
Parse command line arguments for gallery examples.
Definition arg_parser.cpp:4
auto main() -> int
Definition gallery_animate_sin_wave.cpp:48
std::vector< Object > Array
Definition plotly.hpp:27
nlohmann::json Object
Definition plotly.hpp:26
Public Plotly C++ API header.