Skip to content

Implemented wrapper corresponding to tick_params in matplotlib #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions matplotlibcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -1370,6 +1372,30 @@ inline void yticks(const std::vector<Numeric> &ticks, const std::map<std::string
yticks(ticks, {}, keywords);
}

inline void tick_params(const std::map<std::string, std::string>& 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<std::string, std::string>::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
Expand Down