11//
22// Wishlist:
33// * (WIP) Make work for Eigen Vectors and Matrices
4- // * add submodule for our own functions such as spy
54// * export functions in different files for better structure
65// * make plot(y) work with x of unsigned type, or get to the bottom of that
76// problem at least
7+ // * errorbar for xerr and yerr
8+ // * errorbar for yerr of shape (2, N)
89//
910// Changed:
1011// * Implement a better way for named_plot, maybe just as additional
@@ -445,7 +446,8 @@ PyObject *get_2darray(const Matrix &A) {
445446
446447#else // fallback if we don't have numpy: copy every element of the given vector
447448
448- template <typename Vector> PyObject *get_array (const Vector &v) {
449+ template <typename Vector>
450+ PyObject *get_array (const Vector &v) {
449451 detail::_interpreter::get ();
450452 PyObject *list = PyList_New (v.size ());
451453 for (size_t i = 0 ; i < v.size (); ++i) {
@@ -460,8 +462,8 @@ namespace detail {
460462// @brief Since most of the plot commands require the exact same usage apart
461463// from the call to the correct Python function, we encapsulate this
462464// @param pyfunc The matplotlib function to be called with the given arguments
463- // @param x The x vector, must support std::vector methods
464- // @param y The y vector, must support std::vector methods
465+ // @param x The x vector
466+ // @param y The y vector
465467// @param s The formatting string for colour, marker and linestyle
466468// @param keywords Additional keywords, such as label
467469// @return true if plot was successful, false otherwise
@@ -499,19 +501,28 @@ bool plot_base(PyObject *const pyfunc, const VectorX &x, const VectorY &y,
499501
500502} // namespace detail
501503
504+ // @brief standard plot function supporting the args (x, y, s, keywords)
505+ // @param x The x vector
506+ // @param y The y vector
507+ // @param s The formatting string
508+ // @param keywords Additional keywords
509+ // @return true, if successful, false otherwise
502510template <typename VectorX, typename VectorY>
503511bool plot (const VectorX &x, const VectorY &y, const std::string &s = " " ,
504512 const std::map<std::string, std::string> &keywords = {}) {
505513 return detail::plot_base (detail::_interpreter::get ().s_python_function_plot ,
506514 x, y, s, keywords);
507515}
508516
517+ // @brief standard plot function without formatting string, needed if
518+ // keywords are given but formatting string is not
509519template <typename VectorX, typename VectorY>
510520bool plot (const VectorX &x, const VectorY &y,
511521 const std::map<std::string, std::string> &keywords) {
512522 return plot (x, y, " " , keywords);
513523}
514524
525+ // @brief standard plot function if x data is not specified
515526template <typename VectorY = std::vector<double >>
516527bool plot (const VectorY &y, const std::string &format = " " ,
517528 const std::map<std::string, std::string> &keywords = {}) {
@@ -524,6 +535,8 @@ bool plot(const VectorY &y, const std::string &format = "",
524535 return plot (x, y, format);
525536}
526537
538+ // @brief standard plot function if x data is not specified and the formatting
539+ // string is missing
527540template <typename VectorY = std::vector<double >>
528541bool plot (const VectorY &y,
529542 const std::map<std::string, std::string> &keywords) {
@@ -534,6 +547,7 @@ bool plot(const VectorY &y,
534547 return plot (x, y, " " , keywords);
535548}
536549
550+ // @brief loglog plot function, see `plot` for more detail
537551template <typename VectorX, typename VectorY>
538552bool loglog (const VectorX &x, const VectorY &y, const std::string &s = " " ,
539553 const std::map<std::string, std::string> &keywords = {}) {
@@ -567,6 +581,7 @@ bool loglog(const VectorY &y,
567581 return loglog (x, y, " " , keywords);
568582}
569583
584+ // @brief semilogx plot function, see `plot` for more detail
570585template <typename VectorX, typename VectorY>
571586bool semilogx (const VectorX &x, const VectorY &y, const std::string &s = " " ,
572587 const std::map<std::string, std::string> &keywords = {}) {
@@ -601,6 +616,7 @@ bool semilogx(const VectorY &y,
601616 return semilogx (x, y, " " , keywords);
602617}
603618
619+ // @brief semilogy plot function, see `plot` for more detail
604620template <typename VectorX, typename VectorY>
605621bool semilogy (const VectorX &x, const VectorY &y, const std::string &s = " " ,
606622 const std::map<std::string, std::string> &keywords = {}) {
@@ -635,10 +651,13 @@ bool semilogy(const VectorY &y,
635651 return semilogy (x, y, " " , keywords);
636652}
637653
638- template <typename Numeric>
639- void plot_surface (const std::vector<::std::vector<Numeric>> &x,
640- const std::vector<::std::vector<Numeric>> &y,
641- const std::vector<::std::vector<Numeric>> &z,
654+ // @brief plot_surface for datapoints (x_ij, y_ij, z_ij) with i,j = 0..n
655+ // @param x The x values of the datapoints in a matrix
656+ // @param y The y values of the datapoints in a matrix
657+ // @param z The function value of the datapoints in a matrix
658+ // @param keywords Additional keywords
659+ template <typename Matrix>
660+ void plot_surface (const Matrix &x, const Matrix& y, const Matrix& z,
642661 const std::map<std::string, std::string> &keywords =
643662 std::map<std::string, std::string>()) {
644663 // We lazily load the modules here the first time this function is called
0 commit comments