#define _USE_MATH_DEFINES #include #include "../matplotlibcpp.h" #include namespace plt = matplotlibcpp; void update_window(const double x, const double y, const double t, std::vector &xt, std::vector &yt) { const double target_length = 300; const double half_win = (target_length/(2.*sqrt(1.+t*t))); xt[0] = x - half_win; xt[1] = x + half_win; yt[0] = y - half_win*t; yt[1] = y + half_win*t; } int main() { bool use_dynamic_plot = false; bool timeit = true; size_t n = 1000; std::vector x, y; const double w = 0.05; const double a = n/2; for(size_t i=0; i xt(2), yt(2); plt::title("Sample figure"); std::chrono::time_point start, end; start = std::chrono::system_clock::now(); if(use_dynamic_plot) { plt::xlim(x.front(), x.back()); plt::ylim(-a,a); plt::axis("equal"); // plot sin once and for all plt::named_plot("sin", x, y); // prepare plotting the tangent plt::Plot plot("tangent"); plt::legend(); for(size_t i=0; i (end-start).count(); if(use_dynamic_plot) std::cout << "dynamic"; else std::cout << "static"; std::cout << " : " << elapsed_seconds/1000 << " ms\n"; }