From f89f1405e87fea908bfcd12d18f8a9bf87b95214 Mon Sep 17 00:00:00 2001 From: belre9 Date: Mon, 18 Nov 2019 18:43:13 +0900 Subject: [PATCH 1/2] Implemented wrapper corresponding to tick_params in matplotlib --- matplotlibcpp.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/matplotlibcpp.h b/matplotlibcpp.h index 82dbc6b6..9e0ebb35 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -73,6 +73,7 @@ struct _interpreter { PyObject *s_python_function_ylabel; PyObject *s_python_function_xticks; PyObject *s_python_function_yticks; + PyObject *s_python_function_tick_params; PyObject *s_python_function_grid; PyObject *s_python_function_clf; PyObject *s_python_function_errorbar; @@ -1370,6 +1371,30 @@ inline void yticks(const std::vector &ticks, const std::map& keywords, const std::string axis = "both") +{ + // construct positional args + PyObject* args; + args = PyTuple_New(1); + PyTuple_SetItem(args, 0, PyString_FromString(axis.c_str())); + + // construct keyword args + PyObject* kwargs = PyDict_New(); + for (std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) + { + PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str())); + } + + + PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_tick_params, args, kwargs); + + Py_DECREF(args); + Py_DECREF(kwargs); + if (!res) throw std::runtime_error("Call to tick_params() failed"); + + Py_DECREF(res); +} + inline void subplot(long nrows, long ncols, long plot_number) { // construct positional args From e742b16036057af9333c5582f4c741340a759245 Mon Sep 17 00:00:00 2001 From: Belre-Yucho Date: Wed, 20 Nov 2019 08:41:03 +0900 Subject: [PATCH 2/2] safe_import is leaked out --- matplotlibcpp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/matplotlibcpp.h b/matplotlibcpp.h index 9e0ebb35..689f919f 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -204,6 +204,7 @@ struct _interpreter { s_python_function_ylabel = safe_import(pymod, "ylabel"); s_python_function_xticks = safe_import(pymod, "xticks"); s_python_function_yticks = safe_import(pymod, "yticks"); + s_python_function_tick_params = safe_import(pymod, "tick_params"); s_python_function_grid = safe_import(pymod, "grid"); s_python_function_xlim = safe_import(pymod, "xlim"); s_python_function_ion = safe_import(pymod, "ion");