#define _USE_MATH_DEFINES #include #include #include "../matplotlibcpp.h" #include #include namespace plt = matplotlibcpp; int main() { // Prepare data. int n = 5000; xt::xtensor i = xt::linspace(0, (n-1), n); std::array shape{static_cast(n)}; xt::xtensor w(shape); w.fill(2.0); xt::xtensor x = xt::square(i); xt::xtensor y = xt::sin(2 * xt::numeric_constants::PI * i / 360.0); xt::xtensor z = xt::log(i); std::vector vy(n, 5); // Set the size of output image = 1200x780 pixels plt::figure_size(1200, 780); // Plot line from given x and y data. Color is selected automatically. plt::plot(x, y+1); // Plot a red dashed line from given x and y data. plt::plot(x, w+1, "r--"); plt::plot(x, vy, "g-."); // Plot a line whose name will show up as "log(x)" in the legend. plt::named_plot("log(x)", x, z); plt::named_plot("log(x)+1", x, z+1); // Set x-axis to interval [0,1000000] plt::xlim(0, 1000*1000); // Add graph title plt::title("Sample figure"); // Enable legend. plt::legend(); plt::show(); // save figure //const char* filename = "./basic.png"; //std::cout << "Saving result to " << filename << std::endl;; //plt::save(filename); }