#include<cmath>#include<matplot/matplot.h>intmain(){usingnamespacematplot;fplot([](doublex){returnsin(x);},std::array<double,2>{-2*pi,2*pi});grid(on);title("sin(x) from -2π to 2π");xlabel("x");ylabel("y");autoax=gca();ax->x_axis().tick_values(iota(-2*pi,pi/2,2*pi));ax->x_axis().ticklabels({"-2π","-3π/2","-π","-π/2","0","π/2","π","3π/2","2π"});show();return0;}
Instead of storing data points, the objects function line and string function store a function as a lambda function or as a string with an expression. These objects use lazy evaluation to generate absolute data points. The data is generated only when the draw function is called.