1
1
//
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:
4
10
// * Implement a better way for named_plot, maybe just as additional
5
11
// method with extra keyword
6
12
// * add location keyword for legend
7
- // * add submodule for our own functions such as spy
8
13
//
9
14
10
15
#pragma once
@@ -446,8 +451,7 @@ namespace detail {
446
451
// @param s The formatting string for colour, marker and linestyle
447
452
// @param keywords Additional keywords, such as label
448
453
// @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>
451
455
bool plot_base (PyObject *const pyfunc, const VectorX &x, const VectorY &y,
452
456
const std::string &s = " " ,
453
457
const std::map<std::string, std::string> &keywords = {}) {
@@ -497,11 +501,10 @@ bool plot(const VectorX &x, const VectorY &y,
497
501
template <typename VectorY = std::vector<double >>
498
502
bool plot (const VectorY &y, const std::string &format = " " ,
499
503
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)
505
508
x.at (i) = i;
506
509
507
510
return plot (x, y, format);
@@ -510,8 +513,8 @@ bool plot(const VectorY &y, const std::string &format = "",
510
513
template <typename VectorY = std::vector<double >>
511
514
bool plot (const VectorY &y,
512
515
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)
515
518
x.at (i) = i;
516
519
517
520
return plot (x, y, " " , keywords);
@@ -1666,7 +1669,6 @@ ginput(const int numClicks = 1,
1666
1669
return out;
1667
1670
}
1668
1671
1669
- // Actually, is there any reason not to call this automatically for every plot?
1670
1672
inline void tight_layout () {
1671
1673
PyObject *res = PyObject_CallObject (
1672
1674
detail::_interpreter::get ().s_python_function_tight_layout ,
@@ -1678,15 +1680,16 @@ inline void tight_layout() {
1678
1680
Py_DECREF (res);
1679
1681
}
1680
1682
1681
- #if 0
1682
1683
// recursion stop for the below
1683
1684
template <typename ... Args> bool plot () { return true ; }
1684
1685
1686
+ // enable plotting of multiple triples (x, y, format)
1685
1687
template <typename A, typename B, typename ... Args>
1686
1688
bool plot (const A &a, const B &b, const std::string &format, Args... args) {
1687
1689
return plot (a, b, format) && plot (args...);
1688
1690
}
1689
1691
1692
+ #if 0
1690
1693
/*
1691
1694
* This group of plot() functions is needed to support initializer lists, i.e.
1692
1695
* calling plot( {1,2,3,4} )
0 commit comments