Skip to content

Commit 215741e

Browse files
committed
restructure initializer_list + fix *ylim()
initialiser lists work only for plot(y) not plot(x,y) due to conflict with plot(y, string), as initialiser lists can also be used for strings. also the below plot(.. Args) etc is redundant with default template arguments, thus for plot(y) add the default std::vector<double>. (not for plot(x,y) since init.lists dont work anyways)
1 parent 993fed1 commit 215741e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

matplotlibcpp.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ namespace detail {
446446
// @param s The formatting string for colour, marker and linestyle
447447
// @param keywords Additional keywords, such as label
448448
// @return true if plot was successful, false otherwise
449-
template <typename VectorX, typename VectorY>
449+
template <typename VectorX = std::vector<double>,
450+
typename VectorY = std::vector<double>>
450451
bool plot_base(PyObject *const pyfunc, const VectorX &x, const VectorY &y,
451452
const std::string &s = "",
452453
const std::map<std::string, std::string> &keywords = {}) {
@@ -493,7 +494,7 @@ bool plot(const VectorX &x, const VectorY &y,
493494
return plot(x, y, "", keywords);
494495
}
495496

496-
template <typename VectorY>
497+
template <typename VectorY = std::vector<double>>
497498
bool plot(const VectorY &y, const std::string &format = "",
498499
const std::map<std::string, std::string> &keywords = {}) {
499500
// TODO can this be <size_t> or do we need <typename Vector::value_type>?
@@ -506,7 +507,7 @@ bool plot(const VectorY &y, const std::string &format = "",
506507
return plot(x, y, format);
507508
}
508509

509-
template <typename VectorY>
510+
template <typename VectorY = std::vector<double>>
510511
bool plot(const VectorY &y,
511512
const std::map<std::string, std::string> &keywords) {
512513
std::vector<std::size_t> x(y.size());
@@ -529,7 +530,7 @@ bool loglog(const VectorX &x, const VectorY &y,
529530
return loglog(x, y, "", keywords);
530531
}
531532

532-
template <typename VectorY>
533+
template <typename VectorY = std::vector<double>>
533534
bool loglog(const VectorY &y, const std::string &s = "",
534535
const std::map<std::string, std::string> &keywords = {}) {
535536
std::vector<std::size_t> x(y.size());
@@ -539,7 +540,7 @@ bool loglog(const VectorY &y, const std::string &s = "",
539540
return loglog(x, y, s, keywords);
540541
}
541542

542-
template <typename VectorY>
543+
template <typename VectorY = std::vector<double>>
543544
bool loglog(const VectorY &y,
544545
const std::map<std::string, std::string> &keywords) {
545546
std::vector<std::size_t> x(y.size());
@@ -1250,8 +1251,8 @@ inline double *ylim() {
12501251
PyObject *args = PyTuple_New(0);
12511252
PyObject *res = PyObject_CallObject(
12521253
detail::_interpreter::get().s_python_function_ylim, args);
1253-
PyObject *left = PyTuple_GetItem(res, 0);
1254-
PyObject *right = PyTuple_GetItem(res, 1);
1254+
PyObject *bottom = PyTuple_GetItem(res, 0);
1255+
PyObject *top = PyTuple_GetItem(res, 1);
12551256

12561257
double *arr = new double[2];
12571258
arr[0] = PyFloat_AsDouble(bottom);
@@ -1663,6 +1664,7 @@ inline void tight_layout() {
16631664
Py_DECREF(res);
16641665
}
16651666

1667+
#if 0
16661668
// recursion stop for the below
16671669
template <typename... Args> bool plot() { return true; }
16681670

@@ -1688,6 +1690,7 @@ inline bool plot(const std::vector<double> &x, const std::vector<double> &y,
16881690
const std::map<std::string, std::string> &keywords) {
16891691
return plot<std::vector<double>, std::vector<double>>(x, y, keywords);
16901692
}
1693+
#endif
16911694

16921695
/*
16931696
* This class allows dynamic plots, ie changing the plotted data without

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy