@@ -61,6 +61,7 @@ struct _interpreter {
6161 PyObject *s_python_function_imshow;
6262 PyObject *s_python_function_scatter;
6363 PyObject *s_python_function_subplot;
64+ PyObject *s_python_function_subplot2grid;
6465 PyObject *s_python_function_legend;
6566 PyObject *s_python_function_xlim;
6667 PyObject *s_python_function_ion;
@@ -193,6 +194,7 @@ struct _interpreter {
193194 s_python_function_hist = safe_import (pymod," hist" );
194195 s_python_function_scatter = safe_import (pymod," scatter" );
195196 s_python_function_subplot = safe_import (pymod, " subplot" );
197+ s_python_function_subplot2grid = safe_import (pymod, " subplot2grid" );
196198 s_python_function_legend = safe_import (pymod, " legend" );
197199 s_python_function_ylim = safe_import (pymod, " ylim" );
198200 s_python_function_title = safe_import (pymod, " title" );
@@ -362,6 +364,9 @@ bool plot(const std::vector<Numeric> &x, const std::vector<Numeric> &y, const st
362364 return res;
363365}
364366
367+ // TODO - it should be possible to make this work by implementing
368+ // a non-numpy alternative for `get_2darray()`.
369+ #ifndef WITHOUT_NUMPY
365370template <typename Numeric>
366371void plot_surface (const std::vector<::std::vector<Numeric>> &x,
367372 const std::vector<::std::vector<Numeric>> &y,
@@ -453,6 +458,8 @@ void plot_surface(const std::vector<::std::vector<Numeric>> &x,
453458 Py_DECREF (kwargs);
454459 if (res) Py_DECREF (res);
455460}
461+ #endif // WITHOUT_NUMPY
462+
456463
457464template <typename Numeric>
458465bool stem (const std::vector<Numeric> &x, const std::vector<Numeric> &y, const std::map<std::string, std::string>& keywords)
@@ -1073,7 +1080,6 @@ bool named_loglog(const std::string& name, const std::vector<Numeric>& x, const
10731080 PyTuple_SetItem (plot_args, 0 , xarray);
10741081 PyTuple_SetItem (plot_args, 1 , yarray);
10751082 PyTuple_SetItem (plot_args, 2 , pystring);
1076-
10771083 PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_loglog , plot_args, kwargs);
10781084
10791085 Py_DECREF (kwargs);
@@ -1379,6 +1385,31 @@ inline void subplot(long nrows, long ncols, long plot_number)
13791385 Py_DECREF (res);
13801386}
13811387
1388+ void subplot2grid (long nrows, long ncols, long rowid=0 , long colid=0 , long rowspan=1 , long colspan=1 )
1389+ {
1390+ PyObject* shape = PyTuple_New (2 );
1391+ PyTuple_SetItem (shape, 0 , PyLong_FromLong (nrows));
1392+ PyTuple_SetItem (shape, 1 , PyLong_FromLong (ncols));
1393+
1394+ PyObject* loc = PyTuple_New (2 );
1395+ PyTuple_SetItem (loc, 0 , PyLong_FromLong (rowid));
1396+ PyTuple_SetItem (loc, 1 , PyLong_FromLong (colid));
1397+
1398+ PyObject* args = PyTuple_New (4 );
1399+ PyTuple_SetItem (args, 0 , shape);
1400+ PyTuple_SetItem (args, 1 , loc);
1401+ PyTuple_SetItem (args, 2 , PyLong_FromLong (rowspan));
1402+ PyTuple_SetItem (args, 3 , PyLong_FromLong (colspan));
1403+
1404+ PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_subplot2grid , args);
1405+ if (!res) throw std::runtime_error (" Call to subplot2grid() failed." );
1406+
1407+ Py_DECREF (shape);
1408+ Py_DECREF (loc);
1409+ Py_DECREF (args);
1410+ Py_DECREF (res);
1411+ }
1412+
13821413inline void title (const std::string &titlestr, const std::map<std::string, std::string> &keywords = {})
13831414{
13841415 PyObject* pytitlestr = PyString_FromString (titlestr.c_str ());
0 commit comments