matplotlib-cpp icon indicating copy to clipboard operation
matplotlib-cpp copied to clipboard

Plot3 and Plot_Surface window cannot be updated with new data in loops

Open msk2000 opened this issue 2 years ago • 1 comments

You can put the 2d plots in a for loop and it will result in the new data being plotting inside the same open figure window.

However, for 3d plots like plot3 and plot_surface, doing this exact same thing will cause a brand new figure window to spawn. What is even worse is that every window remains fully active and updating all at once!

I'd greatly appreciate if someone helped me overcome this annoying bug which makes all 3d plots unusable for me.

msk2000 avatar Jul 06 '23 18:07 msk2000

You can specify the figure handle of function plot3, which default value is 0:

void plot3(const std::vector<Numeric> &x,
                  const std::vector<Numeric> &y,
                  const std::vector<Numeric> &z,
                  const std::map<std::string, std::string> &keywords =
                      std::map<std::string, std::string>(),
                  const long fig_number=0);

such as:

     map<string, string> set_1, set_2, set_3;
     set_1.insert({"label", "system trajectory"});
     set_2.insert({"label", "control polygon"});
     set_3.insert({"label", "control points"});
     auto fg=plt::figure();//figure handle
     plt::plot3(Cu[0], Cu[1], Cu[2], set_1,fg);
     plt::plot3(Cu[3], Cu[4], Cu[5], set_2, fg);
     plt::scatter(Cu[3], Cu[4], Cu[5], 1, set_3, fg);
     plt::xlabel("x");
     plt::ylabel("y");
     plt::set_zlabel("z");
     plt::legend();
     plt::show();

Then the call of plot3 and scatter will show in one figure.

also can refer to https://github.com/lava/matplotlib-cpp/issues/306#issuecomment-1455186383

ghost avatar Jul 23 '23 07:07 ghost