@@ -62,6 +62,8 @@ struct _interpreter {
6262 PyObject *s_python_empty_tuple;
6363 PyObject *s_python_function_stem;
6464 PyObject *s_python_function_xkcd;
65+ PyObject *s_python_function_text;
66+ PyObject *s_python_function_suptitle;
6567
6668 /* For now, _interpreter is implemented as a singleton since its currently not possible to have
6769 multiple independent embedded python interpreters without patching the python source code
@@ -165,6 +167,8 @@ struct _interpreter {
165167 s_python_function_tight_layout = PyObject_GetAttrString (pymod, " tight_layout" );
166168 s_python_function_stem = PyObject_GetAttrString (pymod, " stem" );
167169 s_python_function_xkcd = PyObject_GetAttrString (pymod, " xkcd" );
170+ s_python_function_text = PyObject_GetAttrString (pymod, " text" );
171+ s_python_function_suptitle = PyObject_GetAttrString (pymod, " suptitle" );
168172
169173 if ( !s_python_function_show
170174 || !s_python_function_close
@@ -195,6 +199,8 @@ struct _interpreter {
195199 || !s_python_function_tight_layout
196200 || !s_python_function_stem
197201 || !s_python_function_xkcd
202+ || !s_python_function_text
203+ || !s_python_function_suptitle
198204 ) { throw std::runtime_error (" Couldn't find required function!" ); }
199205
200206 if ( !PyFunction_Check (s_python_function_show)
@@ -225,6 +231,8 @@ struct _interpreter {
225231 || !PyFunction_Check (s_python_function_errorbar)
226232 || !PyFunction_Check (s_python_function_stem)
227233 || !PyFunction_Check (s_python_function_xkcd)
234+ || !PyFunction_Check (s_python_function_text)
235+ || !PyFunction_Check (s_python_function_suptitle)
228236 ) { throw std::runtime_error (" Python object is unexpectedly not a PyFunction." ); }
229237
230238 s_python_empty_tuple = PyTuple_New (0 );
@@ -788,6 +796,22 @@ bool stem(const std::vector<Numeric>& y, const std::string& format = "")
788796 return stem (x, y, format);
789797}
790798
799+ template <typename Numeric>
800+ void text (Numeric x, Numeric y, const std::string& format = " " )
801+ {
802+ PyObject* args = PyTuple_New (3 );
803+ PyTuple_SetItem (args, 0 , PyFloat_FromDouble (x));
804+ PyTuple_SetItem (args, 1 , PyFloat_FromDouble (y));
805+ PyTuple_SetItem (args, 2 , PyString_FromString (format.c_str ()));
806+
807+ PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_text , args);
808+ if (!res) throw std::runtime_error (" Call to text() failed." );
809+
810+ Py_DECREF (args);
811+ Py_DECREF (res);
812+ }
813+
814+
791815inline void figure ()
792816{
793817 PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_figure , detail::_interpreter::get ().s_python_empty_tuple );
@@ -807,7 +831,7 @@ inline void figure_size(size_t w, size_t h)
807831 PyDict_SetItemString (kwargs, " figsize" , size);
808832 PyDict_SetItemString (kwargs, " dpi" , PyLong_FromSize_t (dpi));
809833
810- PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_figure ,
834+ PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_figure ,
811835 detail::_interpreter::get ().s_python_empty_tuple , kwargs);
812836
813837 Py_DECREF (kwargs);
@@ -931,7 +955,7 @@ inline void xticks(const std::vector<Numeric> &ticks, const std::vector<std::str
931955 Py_DECREF (args);
932956 Py_DECREF (kwargs);
933957 if (!res) throw std::runtime_error (" Call to xticks() failed" );
934-
958+
935959 Py_DECREF (res);
936960}
937961
@@ -978,7 +1002,7 @@ inline void yticks(const std::vector<Numeric> &ticks, const std::vector<std::str
9781002 Py_DECREF (args);
9791003 Py_DECREF (kwargs);
9801004 if (!res) throw std::runtime_error (" Call to yticks() failed" );
981-
1005+
9821006 Py_DECREF (res);
9831007}
9841008
@@ -1016,6 +1040,19 @@ inline void title(const std::string &titlestr)
10161040 Py_DECREF (res);
10171041}
10181042
1043+ inline void suptitle (const std::string &suptitlestr)
1044+ {
1045+ PyObject* pysuptitlestr = PyString_FromString (suptitlestr.c_str ());
1046+ PyObject* args = PyTuple_New (1 );
1047+ PyTuple_SetItem (args, 0 , pysuptitlestr);
1048+
1049+ PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_suptitle , args);
1050+ if (!res) throw std::runtime_error (" Call to suptitle() failed." );
1051+
1052+ Py_DECREF (args);
1053+ Py_DECREF (res);
1054+ }
1055+
10191056inline void axis (const std::string &axisstr)
10201057{
10211058 PyObject* str = PyString_FromString (axisstr.c_str ());
0 commit comments