This gallery example demonstrates creating a basic sine wave plot using Plotly.cpp. It showcases fundamental plotting capabilities with mathematical function visualization over a continuous domain.
Features demonstrated:
- Mathematical function plotting using scatter trace type
- Continuous curve generation with linspace utility
- Basic trigonometric function visualization (sine wave)
- Simple plot creation with minimal configuration
- Standard domain range (-2π to 2π) for complete wave cycles
- High-resolution curve with 200 data points for smooth visualization
Mathematical concepts:
- Sine function: y = sin(x)
- Domain: [-2π, 2π] covering two complete oscillation cycles
- Amplitude: 1.0 (standard unit amplitude)
- Period: 2π (standard sine wave period)
This example serves as an introduction to basic mathematical function plotting and demonstrates the ease of creating smooth curves with Plotly.cpp's scatter trace functionality.
Sine Wave Mathematical Function
#include <cmath>
#include <vector>
auto main(
int argc,
char *argv[]) ->
int {
auto x =
linspace(-2 * M_PI, 2 * M_PI, 200);
std::vector<double> y;
y.reserve(x.size());
for (const auto &xi : x) {
y.push_back(std::sin(xi));
}
{"x", x},
{"y", y},
{"type", "scatter"},
};
std::vector<plotly::Object> data = {trace};
if (!args.headless) {
} else {
{"width", 800},
{"height", 600},
{"filename", "sin_curve"}};
}
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
auto linspace(double a, double b, int n) -> std::vector< double >
Create a linearly spaced vector of values between two endpoints.
Definition linspace.cpp:4
nlohmann::json Object
Definition plotly.hpp:26
Public Plotly C++ API header.