@@ -20,6 +20,7 @@ namespace matplotlibcpp {
2020 PyObject *s_python_function_save;
2121 PyObject *s_python_function_figure;
2222 PyObject *s_python_function_plot;
23+ PyObject *s_python_function_subplot;
2324 PyObject *s_python_function_legend;
2425 PyObject *s_python_function_xlim;
2526 PyObject *s_python_function_ylim;
@@ -63,6 +64,7 @@ namespace matplotlibcpp {
6364 s_python_function_show = PyObject_GetAttrString (pymod, " show" );
6465 s_python_function_figure = PyObject_GetAttrString (pymod, " figure" );
6566 s_python_function_plot = PyObject_GetAttrString (pymod, " plot" );
67+ s_python_function_subplot = PyObject_GetAttrString (pymod, " subplot" );
6668 s_python_function_legend = PyObject_GetAttrString (pymod, " legend" );
6769 s_python_function_ylim = PyObject_GetAttrString (pymod, " ylim" );
6870 s_python_function_title = PyObject_GetAttrString (pymod, " title" );
@@ -76,6 +78,7 @@ namespace matplotlibcpp {
7678 if ( !s_python_function_show
7779 || !s_python_function_figure
7880 || !s_python_function_plot
81+ || !s_python_function_subplot
7982 || !s_python_function_legend
8083 || !s_python_function_ylim
8184 || !s_python_function_title
@@ -91,6 +94,7 @@ namespace matplotlibcpp {
9194 if ( !PyFunction_Check (s_python_function_show)
9295 || !PyFunction_Check (s_python_function_figure)
9396 || !PyFunction_Check (s_python_function_plot)
97+ || !PyFunction_Check (s_python_function_subplot)
9498 || !PyFunction_Check (s_python_function_legend)
9599 || !PyFunction_Check (s_python_function_ylim)
96100 || !PyFunction_Check (s_python_function_title)
@@ -261,6 +265,20 @@ namespace matplotlibcpp {
261265 Py_DECREF (res);
262266 }
263267
268+ inline void subplot (long nrows, long ncols, long plot_number) {
269+ // construct positional args
270+ PyObject* args = PyTuple_New (3 );
271+ PyTuple_SetItem (args, 0 , PyFloat_FromDouble (nrows));
272+ PyTuple_SetItem (args, 1 , PyFloat_FromDouble (ncols));
273+ PyTuple_SetItem (args, 2 , PyFloat_FromDouble (plot_number));
274+
275+ PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_subplot , args);
276+ if (!res) throw std::runtime_error (" Call to subplot() failed." );
277+
278+ Py_DECREF (args);
279+ Py_DECREF (res);
280+ }
281+
264282 inline void title (const std::string &titlestr)
265283 {
266284 PyObject* pytitlestr = PyString_FromString (titlestr.c_str ());
0 commit comments