8000 generic vector implementation of semilogx and -y · Cryoris/matplotlib-cpp@9cdd5ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 9cdd5ae

Browse files
committed
generic vector implementation of semilogx and -y
1 parent 8fcd538 commit 9cdd5ae

File tree

1 file changed

+68
-50
lines changed

1 file changed

+68
-50
lines changed

matplotlibcpp.h

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,74 @@ bool loglog(const VectorY &y,
549549
return loglog(x, y, "", keywords);
550550
}
551551

552+
template <typename VectorX, typename VectorY>
553+
bool semilogx(const VectorX &x, const VectorY &y, const std::string &s = "",
554+
const std::map<std::string, std::string> &keywords = {}) {
555+
return detail::plot_base(
556+
detail::_interpreter::get().s_python_function_semilogx, x, y, s,
557+
keywords);
558+
}
559+
560+
template <typename VectorX, typename VectorY>
561+
bool semilogx(const VectorX &x, const VectorY &y,
562+
const std::map<std::string, std::string> &keywords) {
563+
return semilogx(x, y, "", keywords);
564+
}
565+
566+
template <typename VectorY>
567+
bool semilogx(const VectorY &y, const std::string &s = "",
568+
const std::map<std::string, std::string> &keywords = {}) {
569+
std::vector<std::size_t> x(y.size());
570+
for (std::size_t i = 0; i < x.size(); ++i)
571+
x.at(i) = i + 1; // in semilogx scale the values shouldn't be zero
572+
573+
return semilogx(x, y, s, keywords);
574+
}
575+
576+
template <typename VectorY>
577+
bool semilogx(const VectorY &y,
578+
const std::map<std::string, std::string> &keywords) {
579+
std::vector<std::size_t> x(y.size());
580+
for (std::size_t i = 0; i < x.size(); ++i)
581+
x.at(i) = i + 1; // in semilogx scale the values shouldn't be zero
582+
583+
return semilogx(x, y, "", keywords);
584+
}
585+
586+
template <typename VectorX, typename VectorY>
587+
bool semilogy(const VectorX &x, const VectorY &y, const std::string &s = "",
588+
const std::map<std::string, std::string> &keywords = {}) {
589+
return detail::plot_base(
590+
detail::_interpreter::get().s_python_function_semilogy, x, y, s,
591+
keywords);
592+
}
593+
594+
template <typename VectorX, typename VectorY>
595+
bool semilogy(const VectorX &x, const VectorY &y,
596+
const std::map<std::string, std::string> &keywords) {
597+
return semilogy(x, y, "", keywords);
598+
}
599+
600+
template <typename VectorY>
601+
bool semilogy(const VectorY &y, const std::string &s = "",
602+
const std::map<std::string, std::string> &keywords = {}) {
603+
std::vector<std::size_t> x(y.size());
604+
for (std::size_t i = 0; i < x.size(); ++i)
605+
x.at(i) = i + 1; // in semilogx scale the values shouldn't be zero
606+
607+
return semilogy(x, y, s, keywords);
608+
}
609+
610+
template <typename VectorY>
611+
bool semilogy(const VectorY &y,
612+
const std::map<std::string, std::string> &keywords) {
613+
std::vector<std::size_t> x(y.size());
614+
for (std::size_t i = 0; i < x.size(); ++i)
615+
x.at(i) = i + 1; // in semilogx scale the values shouldn't be zero
616+
617+
return semilogy(x, y, "", keywords);
618+
}
619+
552620
template <typename Numeric>
553621
void plot_surface(const std::vector<::std::vector<Numeric>> &x,
554622
const std::vector<::std::vector<Numeric>> &y,
@@ -953,56 +1021,6 @@ bool stem(const std::vector<NumericX> &x, const std::vector<NumericY> &y,
9531021
return res;
9541022
}
9551023

956-
template <typename NumericX, typename NumericY>
957-
bool semilogx(const std::vector<NumericX> &x, const std::vector<NumericY> &y,
958-
const std::string &s = "") {
959-
assert(x.size() == y.size());
960-
961-
PyObject *xarray = get_array(x);
962-
PyObject *yarray = get_array(y);
963-
964-
PyObject *pystring = PyString_FromString(s.c_str());
965-
966-
PyObject *plot_args = PyTuple_New(3);
967-
PyTuple_SetItem(plot_args, 0, xarray);
968-
PyTuple_SetItem(plot_args, 1, yarray);
969-
PyTuple_SetItem(plot_args, 2, pystring);
970-
971-
PyObject *res = PyObject_CallObject(
972-
detail::_interpreter::get().s_python_function_semilogx, plot_args);
973-
974-
Py_DECREF(plot_args);
975-
if (res)
976-
Py_DECREF(res);
977-
978-
return res;
979-
}
980-
981-
template <typename NumericX, typename NumericY>
982-
bool semilogy(const std::vector<NumericX> &x, const std::vector<NumericY> &y,
983-
const std::string &s = "") {
984-
assert(x.size() == y.size());
985-
986-
PyObject *xarray = get_array(x);
987-
PyObject *yarray = get_array(y);
988-
989-
PyObject *pystring = PyString_FromString(s.c_str());
990-
991-
PyObject *plot_args = PyTuple_New(3);
992-
PyTuple_SetItem(plot_args, 0, xarray);
993-
PyTuple_SetItem(plot_args, 1, yarray);
994-
PyTuple_SetItem(plot_args, 2, pystring);
995-
996-
PyObject *res = PyObject_CallObject(
997-
detail::_interpreter::get().s_python_function_semilogy, plot_args);
998-
999-
Py_DECREF(plot_args);
1000-
if (res)
1001-
Py_DECREF(res);
1002-
1003-
return res;
1004-
}
1005-
10061024
template <typename NumericX, typename NumericY>
10071025
bool errorbar(const std::vector<NumericX> &x, const std::vector<NumericY> &y,
10081026
const std::vector<NumericX> &yerr,

0 commit comments

Comments< 3175 /div> (0)
0