Use these examples to understand how to quickly use the library for data visualization. If you are interested in understanding how the library works, you can later read the details in the complete article.
Setters return a reference to *this to allow method chaining:
1
plot(x,y)->line_width(2).color("red");
Tip
These examples use free-standing functions to create plots. You can also use a object-oriented style for plots. We discuss these coding styles in the Section Coding Styles.
#include<matplot/matplot.h>#include<set>intmain(){usingnamespacematplot;std::vector<double>x=linspace(-pi,+pi,20);// test with set, just because...std::set<double>x2(x.begin(),x.end());std::vector<double>y=transform(x,[](autox){returntan(sin(x))-sin(tan(x));});plot(x2,y,"--gs")->line_width(2).marker_size(10).marker_color("b").marker_face_color({.5,.5,.5});show();return0;}
1 2 3 4 5 6 7 8 910111213141516
#include<cmath>#include<matplot/matplot.h>intmain(){usingnamespacematplot;std::vector<double>x=linspace(0,10,150);std::vector<double>y=transform(x,[](autox){returncos(5*x);});plot(x,y)->color({0.f,0.7f,0.9f});title("2-D Line Plot");xlabel("x");ylabel("cos(5x)");show();return0;}