matplotlib-cpp
matplotlib-cpp copied to clipboard
3D line plot not showing any data
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:
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.
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!