@@ -31,6 +31,7 @@ namespace matplotlibcpp {
3131
3232 struct _interpreter {
3333 PyObject *s_python_function_show;
34+ PyObject *s_python_function_close;
3435 PyObject *s_python_function_draw;
3536 PyObject *s_python_function_pause;
3637 PyObject *s_python_function_save;
@@ -122,6 +123,7 @@ namespace matplotlibcpp {
122123 if (!pylabmod) { throw std::runtime_error (" Error loading module pylab!" ); }
123124
124125 s_python_function_show = PyObject_GetAttrString (pymod, " show" );
126+ s_python_function_close = PyObject_GetAttrString (pymod, " close" );
125127 s_python_function_draw = PyObject_GetAttrString (pymod, " draw" );
126128 s_python_function_pause = PyObject_GetAttrString (pymod, " pause" );
127129 s_python_function_figure = PyObject_GetAttrString (pymod, " figure" );
@@ -150,6 +152,7 @@ namespace matplotlibcpp {
150152 s_python_function_xkcd = PyObject_GetAttrString (pymod, " xkcd" );
151153
152154 if ( !s_python_function_show
155+ || !s_python_function_close
153156 || !s_python_function_draw
154157 || !s_python_function_pause
155158 || !s_python_function_figure
@@ -179,6 +182,7 @@ namespace matplotlibcpp {
179182 ) { throw std::runtime_error (" Couldn't find required function!" ); }
180183
181184 if ( !PyFunction_Check (s_python_function_show)
185+ || !PyFunction_Check (s_python_function_close)
182186 || !PyFunction_Check (s_python_function_draw)
183187 || !PyFunction_Check (s_python_function_pause)
184188 || !PyFunction_Check (s_python_function_figure)
@@ -913,6 +917,17 @@ namespace matplotlibcpp {
913917 Py_DECREF (res);
914918 }
915919
920+ inline void close ()
921+ {
922+ PyObject* res = PyObject_CallObject (
923+ detail::_interpreter::get ().s_python_function_close ,
924+ detail::_interpreter::get ().s_python_empty_tuple );
925+
926+ if (!res) throw std::runtime_error (" Call to close() failed." );
927+
928+ Py_DECREF (res);
929+ }
930+
916931 inline void xkcd () {
917932 PyObject* res;
918933 PyObject *kwargs = PyDict_New ();
0 commit comments