3D Surface Plot Example
This example demonstrates how to create three-dimensional surface plots using plotly.cpp, visualizing mathematical functions in 3D space.
What You'll Learn
- Creating 3D surface plots from mathematical functions
- Generating 2D grid data for surface visualization
- Working with colorscales and surface styling
- Mathematical function visualization techniques
Sample Output
The example creates a 3D surface plot of the function:
This creates a ripple effect emanating from the center, visualized with the Viridis colorscale for better depth perception.
3D Surface Plot Example Output
- See also
- plotly::Figure For the main plotting interface
#include <cmath>
#include <vector>
auto main(
int argc,
char *argv[]) ->
int {
int size = 50;
std::vector<std::vector<double>> z(size, std::vector<double>(size));
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
double x = (i - size / 2.0) * 0.2;
double y = (j - size / 2.0) * 0.2;
z[i][j] = std::sin(std::sqrt(x * x + y * y));
}
}
{"z", z}, {"type", "surface"}, {"colorscale", "Viridis"}};
if (!args.headless) {
} else {
{"width", 800},
{"height", 600},
{"filename", "3d_surface"}};
}
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.