This gallery example demonstrates creating plots with multiple traces and advanced styling options using Plotly.cpp. It showcases different line styles, colors, and mathematical functions plotted together with custom legend configuration.
#include <cmath>
#include <vector>
auto main(
int argc,
char *argv[]) ->
int {
int n = 5000;
std::vector<double> x(n), y(n), z(n), w(n, 2.0);
for (int i = 0; i < n; ++i) {
x[i] = i * i;
y[i] = std::sin(2 * M_PI * i / 360.0);
z[i] = std::log(i + 1);
}
{"y", y},
{"type", "scatter"},
{"mode", "lines"},
{"name", "sin(2πi/360)"}};
{"x", x},
{"y", w},
{"type", "scatter"},
{"mode", "lines"},
{"name", "constant line (y=2)"}};
{"y", z},
{"type", "scatter"},
{"mode", "lines"},
{"name", "log(x)"}};
{"title", {{"text", "Sample figure"}}},
{"xaxis",
{
{"title", {{"text", "X values"}}},
}},
{"yaxis", {{"title", {{"text", "Y values"}}}}},
{"showlegend", true},
{"width", 1200},
{"height", 780}};
std::vector<plotly::Object> data = {trace1, trace2, trace3};
if (!args.headless) {
} else {
{"width", 1200},
{"height", 780},
{"filename", "multi_trace_styling"}};
}
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.