diff --git a/matplotlibcpp.h b/matplotlibcpp.h index d95d46a..0bbb5fa 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -2249,6 +2249,7 @@ inline void tick_params(const std::map& keywords, cons Py_DECREF(res); } +/* inline void subplot(long nrows, long ncols, long plot_number) { detail::_interpreter::get(); @@ -2265,6 +2266,38 @@ inline void subplot(long nrows, long ncols, long plot_number) Py_DECREF(args); Py_DECREF(res); } +*/ + +inline void subplot(long nrows, long ncols, long plot_number, + bool sharex = false, bool sharey = false) { + // construct positional args + PyObject* args = PyTuple_New(3); + PyTuple_SetItem(args, 0, PyLong_FromLong(nrows)); + PyTuple_SetItem(args, 1, PyLong_FromLong(ncols)); + PyTuple_SetItem(args, 2, PyLong_FromLong(plot_number)); + + // construct keyword args + PyObject *kwargs = PyDict_New(); + if (sharex) { + PyObject *args = PyTuple_New(0); + PyObject *gca = PyObject_CallObject( + detail::_interpreter::get().s_python_function_gca, args); + PyDict_SetItemString(kwargs, "sharex", gca); + } + if (sharey) { + PyObject *args = PyTuple_New(0); + PyObject *gca = PyObject_CallObject( + detail::_interpreter::get().s_python_function_gca, args); + PyDict_SetItemString(kwargs, "sharey", gca); + } + + PyObject *res = PyObject_Call( + detail::_interpreter::get().s_python_function_subplot, args, kwargs); + if(!res) throw std::runtime_error("Call to subplot() failed."); + + Py_DECREF(args); + Py_DECREF(res); +} inline void subplot2grid(long nrows, long ncols, long rowid=0, long colid=0, long rowspan=1, long colspan=1) {