lava / matplotlib-cpp

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

Adds plot_surface function overloading #232

Open antoinedray opened 3 years ago

antoinedray commented 3 years ago

Added:

Adds bindings to the figure's gca method (matplotlib.figure.Figure.gca):

inline void gca(const std::string projection = "3d")

This allows display of multiple surfaces on the same figure.

See example below:

plt::gca("3d");
plt::plot_surface(x1, y1, z1, {{"cmap", "Blues"}});
plt::plot_surface(x2, y2, z2, {{"cmap", "Reds"}});
plt::show();
antoinedray commented 3 years ago

Update:

Remove gca method as it conflicts with simple surface plotting.

New technique found instead:

Adds plot_surface function overloading:

template <typename Numeric>
void plot_surface(long figure,
                  const std::vector<::std::vector<Numeric>> &x,
                  const std::vector<::std::vector<Numeric>> &y,
                  const std::vector<::std::vector<Numeric>> &z,
                  const std::map<std::string, std::string> &keywords = std::map<std::string, std::string>())

By passing the figure id as parameter, it is now possible to bring multiple surfaces in the same figure:

long id = plt::figure();
plt::plot_surface(id, x1, y1, z1, {{"cmap", "Blues"}});
plt::plot_surface(id, x2, y2, z2, {{"cmap", "Reds"}});
plt::show();
bingjingshidelei commented 5 months ago

Why did I use the second drawing method, instead of drawing the two surfaces in the same display, I just showed the first of them.