diff --git a/matplotlibcpp.h b/matplotlibcpp.h index 82dbc6b6..689f919f 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; @@ -203,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"); @@ -1370,6 +1372,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