@@ -20,6 +20,7 @@ namespace matplotlibcpp {
20
20
PyObject *s_python_function_save;
21
21
PyObject *s_python_function_figure;
22
22
PyObject *s_python_function_plot;
23
+ PyObject *s_python_function_subplot;
23
24
PyObject *s_python_function_legend;
24
25
PyObject *s_python_function_xlim;
25
26
PyObject *s_python_function_ylim;
@@ -63,6 +64,7 @@ namespace matplotlibcpp {
63
64
s_python_function_show = PyObject_GetAttrString (pymod, " show" );
64
65
s_python_function_figure = PyObject_GetAttrString (pymod, " figure" );
65
66
s_python_function_plot = PyObject_GetAttrString (pymod, " plot" );
67
+ s_python_function_subplot = PyObject_GetAttrString (pymod, " subplot" );
66
68
s_python_function_legend = PyObject_GetAttrString (pymod, " legend" );
67
69
s_python_function_ylim = PyObject_GetAttrString (pymod, " ylim" );
68
70
s_python_function_title = PyObject_GetAttrString (pymod, " title" );
@@ -76,6 +78,7 @@ namespace matplotlibcpp {
76
78
if ( !s_python_function_show
77
79
|| !s_python_function_figure
78
80
|| !s_python_function_plot
81
+ || !s_python_function_subplot
79
82
|| !s_python_function_legend
80
83
|| !s_python_function_ylim
81
84
|| !s_python_function_title
@@ -91,6 +94,7 @@ namespace matplotlibcpp {
91
94
if ( !PyFunction_Check (s_python_function_show)
92
95
|| !PyFunction_Check (s_python_function_figure)
93
96
|| !PyFunction_Check (s_python_function_plot)
97
+ || !PyFunction_Check (s_python_function_subplot)
94
98
|| !PyFunction_Check (s_python_function_legend)
95
99
|| !PyFunction_Check (s_python_function_ylim)
96
100
|| !PyFunction_Check (s_python_function_title)
@@ -261,6 +265,20 @@ namespace matplotlibcpp {
261
265
Py_DECREF (res);
262
266
}
263
267
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
+
264
282
inline void title (const std::string &titlestr)
265
283
{
266
284
PyObject* pytitlestr = PyString_FromString (titlestr.c_str ());
0 commit comments