1
1
//
2
2
// Wishlist:
3
3
// * (WIP) Make work for Eigen Vectors and Matrices
4
- // * add submodule for our own functions such as spy
5
4
// * export functions in different files for better structure
6
5
// * make plot(y) work with x of unsigned type, or get to the bottom of that
7
6
// problem at least
7
+ // * errorbar for xerr and yerr
8
+ // * errorbar for yerr of shape (2, N)
8
9
//
9
10
// Changed:
10
11
// * Implement a better way for named_plot, maybe just as additional
@@ -445,7 +446,8 @@ PyObject *get_2darray(const Matrix &A) {
445
446
446
447
#else // fallback if we don't have numpy: copy every element of the given vector
447
448
448
- template <typename Vector> PyObject *get_array (const Vector &v) {
449
+ template <typename Vector>
450
+ PyObject *get_array (const Vector &v) {
449
451
detail::_interpreter::get ();
450
452
PyObject *list = PyList_New (v.size ());
451
453
for (size_t i = 0 ; i < v.size (); ++i) {
@@ -460,8 +462,8 @@ namespace detail {
460
462
// @brief Since most of the plot commands require the exact same usage apart
461
463
// from the call to the correct Python function, we encapsulate this
462
464
// @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
465
467
// @param s The formatting string for colour, marker and linestyle
466
468
// @param keywords Additional keywords, such as label
467
469
// @return true if plot was successful, false otherwise
@@ -499,19 +501,28 @@ bool plot_base(PyObject *const pyfunc, const VectorX &x, const VectorY &y,
499
501
500
502
} // namespace detail
501
503
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
502
510
template <typename VectorX, typename VectorY>
503
511
bool plot (const VectorX &x, const VectorY &y, const std::string &s = " " ,
504
512
const std::map<std::string, std::string> &keywords = {}) {
505
513
return detail::plot_base (detail::_interpreter::get ().s_python_function_plot ,
506
514
x, y, s, keywords);
507
515
}
508
516
517
+ // @brief standard plot function without formatting string, needed if
518
+ // keywords are given but formatting string is not
509
519
template <typename VectorX, typename VectorY>
510
520
bool plot (const VectorX &x, const VectorY &y,
511
521
const std::map<std::string, std::string> &keywords) {
512
522
return plot (x, y, " " , keywords);
513
523
}
514
524
525
+ // @brief standard plot function if x data is not specified
515
526
template <typename VectorY = std::vector<double >>
516
527
bool plot (const VectorY &y, const std::string &format = " " ,
517
528
const std::map<std::string, std::string> &keywords = {}) {
@@ -524,6 +535,8 @@ bool plot(const VectorY &y, const std::string &format = "",
524
535
return plot (x, y, format);
525
536
}
526
537
538
+ // @brief standard plot function if x data is not specified and the formatting
539
+ // string is missing
527
540
template <typename VectorY = std::vector<double >>
528
541
bool plot (const VectorY &y,
529
542
const std::map<std::string, std::string> &keywords) {
@@ -534,6 +547,7 @@ bool plot(const VectorY &y,
534
547
return plot (x, y, " " , keywords);
535
548
}
536
549
550
+ // @brief loglog plot function, see `plot` for more detail
537
551
template <typename VectorX, typename VectorY>
538
552
bool loglog (const VectorX &x, const VectorY &y, const std::string &s = " " ,
539
553
const std::map<std::string, std::string> &keywords = {}) {
@@ -567,6 +581,7 @@ bool loglog(const VectorY &y,
567
581
return loglog (x, y, " " , keywords);
568
582
}
569
583
584
+ // @brief semilogx plot function, see `plot` for more detail
570
585
template <typename VectorX, typename VectorY>
571
586
bool semilogx (const VectorX &x, const VectorY &y, const std::string &s = " " ,
572
587
const std::map<std::string, std::string> &keywords = {}) {
@@ -601,6 +616,7 @@ bool semilogx(const VectorY &y,
601
616
return semilogx (x, y, " " , keywords);
602
617
}
603
618
619
+ // @brief semilogy plot function, see `plot` for more detail
604
620
template <typename VectorX, typename VectorY>
605
621
bool semilogy (const VectorX &x, const VectorY &y, const std::string &s = " " ,
606
622
const std::map<std::string, std::string> &keywords = {}) {
@@ -635,10 +651,13 @@ bool semilogy(const VectorY &y,
635
651
return semilogy (x, y, " " , keywords);
636
652
}
637
653
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,
642
661
const std::map<std::string, std::string> &keywords =
643
662
std::map<std::string, std::string>()) {
644
663
// We lazily load the modules here the first time this function is called
0 commit comments