@@ -62,6 +62,8 @@ struct _interpreter {
62
62
PyObject *s_python_empty_tuple;
63
63
PyObject *s_python_function_stem;
64
64
PyObject *s_python_function_xkcd;
65
+ PyObject *s_python_function_text;
66
+ PyObject *s_python_function_suptitle;
65
67
66
68
/* For now, _interpreter is implemented as a singleton since its currently not possible to have
67
69
multiple independent embedded python interpreters without patching the python source code
@@ -165,6 +167,8 @@ struct _interpreter {
165
167
s_python_function_tight_layout = PyObject_GetAttrString (pymod, " tight_layout" );
166
168
s_python_function_stem = PyObject_GetAttrString (pymod, " stem" );
167
169
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" );
168
172
169
173
if ( !s_python_function_show
170
174
|| !s_python_function_close
@@ -195,6 +199,8 @@ struct _interpreter {
195
199
|| !s_python_function_tight_layout
196
200
|| !s_python_function_stem
197
201
|| !s_python_function_xkcd
202
+ || !s_python_function_text
203
+ || !s_python_function_suptitle
198
204
) { throw std::runtime_error (" Couldn't find required function!" ); }
199
205
200
206
if ( !PyFunction_Check (s_python_function_show)
@@ -225,6 +231,8 @@ struct _interpreter {
225
231
|| !PyFunction_Check (s_python_function_errorbar)
226
232
|| !PyFunction_Check (s_python_function_stem)
227
233
|| !PyFunction_Check (s_python_function_xkcd)
234
+ || !PyFunction_Check (s_python_function_text)
235
+ || !PyFunction_Check (s_python_function_suptitle)
228
236
) { throw std::runtime_error (" Python object is unexpectedly not a PyFunction." ); }
229
237
230
238
s_python_empty_tuple = PyTuple_New (0 );
@@ -788,6 +796,22 @@ bool stem(const std::vector<Numeric>& y, const std::string& format = "")
788
796
return stem (x, y, format);
789
797
}
790
798
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
+
791
815
inline void figure ()
792
816
{
793
817
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)
807
831
PyDict_SetItemString (kwargs, " figsize" , size);
808
832
PyDict_SetItemString (kwargs, " dpi" , PyLong_FromSize_t (dpi));
809
833
810
- PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_figure ,
834
+ PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_figure ,
811
835
detail::_interpreter::get ().s_python_empty_tuple , kwargs);
812
836
813
837
Py_DECREF (kwargs);
@@ -931,7 +955,7 @@ inline void xticks(const std::vector<Numeric> &ticks, const std::vector<std::str
931
955
Py_DECREF (args);
932
956
Py_DECREF (kwargs);
933
957
if (!res) throw std::runtime_error (" Call to xticks() failed" );
934
-
958
+
935
959
Py_DECREF (res);
936
960
}
937
961
@@ -978,7 +1002,7 @@ inline void yticks(const std::vector<Numeric> &ticks, const std::vector<std::str
978
1002
Py_DECREF (args);
979
1003
Py_DECREF (kwargs);
980
1004
if (!res) throw std::runtime_error (" Call to yticks() failed" );
981
-
1005
+
982
1006
Py_DECREF (res);
983
1007
}
984
1008
@@ -1016,6 +1040,19 @@ inline void title(const std::string &titlestr)
1016
1040
Py_DECREF (res);
1017
1041
}
1018
1042
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
+
1019
1056
inline void axis (const std::string &axisstr)
1020
1057
{
1021
1058
PyObject* str = PyString_FromString (axisstr.c_str ());
0 commit comments