11//
2- // Changes:
3- // * Make work for Eigen Vectors and Matrices
2+ // Wishlist:
3+ // * (WIP) Make work for Eigen Vectors and Matrices
4+ // * add submodule for our own functions such as spy
5+ // * export functions in different files for better structure
6+ // * make plot(y) work with x of unsigned type, or get to the bottom of that
7+ // problem at least
8+ //
9+ // Changed:
410// * Implement a better way for named_plot, maybe just as additional
511// method with extra keyword
612// * add location keyword for legend
7- // * add submodule for our own functions such as spy
813//
914
1015#pragma once
@@ -446,8 +451,7 @@ namespace detail {
446451// @param s The formatting string for colour, marker and linestyle
447452// @param keywords Additional keywords, such as label
448453// @return true if plot was successful, false otherwise
449- template <typename VectorX = std::vector<double >,
450- typename VectorY = std::vector<double >>
454+ template <typename VectorX, typename VectorY>
451455bool plot_base (PyObject *const pyfunc, const VectorX &x, const VectorY &y,
452456 const std::string &s = " " ,
453457 const std::map<std::string, std::string> &keywords = {}) {
@@ -497,11 +501,10 @@ bool plot(const VectorX &x, const VectorY &y,
497501template <typename VectorY = std::vector<double >>
498502bool plot (const VectorY &y, const std::string &format = " " ,
499503 const std::map<std::string, std::string> &keywords = {}) {
500- // TODO can this be <size_t> or do we need <typename Vector::value_type>?
501- // before the conversion of this function from vector<Numeric> to Vector
502- // the created vector x was of the same type as y
503- std::vector<std::size_t > x (y.size ());
504- for (std::size_t i = 0 ; i < x.size (); ++i)
504+ // Note: cannot be an unsigned type for some reason, yields an overflow
505+ // problem..
506+ std::vector<int > x (y.size ());
507+ for (int i = 0 ; i < x.size (); ++i)
505508 x.at (i) = i;
506509
507510 return plot (x, y, format);
@@ -510,8 +513,8 @@ bool plot(const VectorY &y, const std::string &format = "",
510513template <typename VectorY = std::vector<double >>
511514bool plot (const VectorY &y,
512515 const std::map<std::string, std::string> &keywords) {
513- std::vector<std:: size_t > x (y.size ());
514- for (std:: size_t i = 0 ; i < x.size (); ++i)
516+ std::vector<int > x (y.size ());
517+ for (int i = 0 ; i < x.size (); ++i)
515518 x.at (i) = i;
516519
517520 return plot (x, y, " " , keywords);
@@ -1666,7 +1669,6 @@ ginput(const int numClicks = 1,
16661669 return out;
16671670}
16681671
1669- // Actually, is there any reason not to call this automatically for every plot?
16701672inline void tight_layout () {
16711673 PyObject *res = PyObject_CallObject (
16721674 detail::_interpreter::get ().s_python_function_tight_layout ,
@@ -1678,15 +1680,16 @@ inline void tight_layout() {
16781680 Py_DECREF (res);
16791681}
16801682
1681- #if 0
16821683// recursion stop for the below
16831684template <typename ... Args> bool plot () { return true ; }
16841685
1686+ // enable plotting of multiple triples (x, y, format)
16851687template <typename A, typename B, typename ... Args>
16861688bool plot (const A &a, const B &b, const std::string &format, Args... args) {
16871689 return plot (a, b, format) && plot (args...);
16881690}
16891691
1692+ #if 0
16901693/*
16911694 * This group of plot() functions is needed to support initializer lists, i.e.
16921695 * calling plot( {1,2,3,4} )
0 commit comments