lava / matplotlib-cpp

Extremely simple yet powerful header-only C++ plotting library built on the popular matplotlib
MIT License
4.27k stars 1.12k forks source link

3D line plot not showing any data #350

Open manumerous opened 11 months ago

manumerous commented 11 months ago

I am trying to use matplotlib-cpp to plot a 3D trajectory but can not get the 3D plot to show any data.

When I plot the 3 axis (x,y,z) separately in a normal 2D plot I can verify that the all data (contained in a std::vector) is correct and bounded:

lorenz_attractor_figure1

However, when I try to plot the data in the 3D line plot, as explained by the provided example, I just get an empty plot. The limits of each axis is correct given the data in plot 1. But the second plot just does not show any data.

lorenz_attractor_figure2

Since I followed the provided example as closely as possible I am not sure how I could fix this. Is this a bug or am I missing something?

The code used to generate the plots is as follows:

  plt::plot(trajectory.getTimeStamps(), trajectory.getSingleStateValues(0), {{"label", "x"}});
  plt::plot(trajectory.getTimeStamps(), trajectory.getSingleStateValues(1), {{"label", "y"}});
  plt::plot(trajectory.getTimeStamps(), trajectory.getSingleStateValues(2), {{"label", "z"}});

  plt::title("Simulated Lorenz Attractor System");
  plt::xlabel("Time [s]");
  plt::ylabel("Position [m]");
  plt::legend();

  plt::show();

  std::map<std::string, std::string> keywords;
  keywords.insert(std::pair<std::string, std::string>("label", "system trajectory"));

  plt::plot3(trajectory.getSingleStateValues(0), trajectory.getSingleStateValues(1), trajectory.getSingleStateValues(2), keywords);
  plt::xlabel("x");
  plt::ylabel("y");
  plt::set_zlabel("z");  // set_zlabel rather than just zlabel, in accordance with the Axes3D method
  plt::legend();
  plt::show();

The full code I used to generate the plots can be found in lorenzSystem.hpp . I am running the code on a Linux Mint 21system using X-Cinnamon Desktop in case that is relevant.

Any help is apprechiated!