@@ -23,6 +23,7 @@ namespace matplotlibcpp {
23
23
PyObject *s_python_function_legend;
24
24
PyObject *s_python_function_xlim;
25
25
PyObject *s_python_function_ylim;
26
+ PyObject *s_python_function_title;
26
27
PyObject *s_python_empty_tuple;
27
28
28
29
/* For now, _interpreter is implemented as a singleton since its currently not possible to have
@@ -60,6 +61,7 @@ namespace matplotlibcpp {
60
61
s_python_function_plot = PyObject_GetAttrString (pymod, " plot" );
61
62
s_python_function_legend = PyObject_GetAttrString (pymod, " legend" );
62
63
s_python_function_ylim = PyObject_GetAttrString (pymod, " ylim" );
64
+ s_python_function_title = PyObject_GetAttrString (pymod, " title" );
63
65
s_python_function_xlim = PyObject_GetAttrString (pymod, " xlim" );
64
66
65
67
s_python_function_save = PyObject_GetAttrString (pylabmod, " savefig" );
@@ -70,6 +72,7 @@ namespace matplotlibcpp {
70
72
|| !s_python_function_plot
71
73
|| !s_python_function_legend
72
74
|| !s_python_function_xlim
75
+ || !s_python_function_title
73
76
|| !s_python_function_ylim)
74
77
{ throw std::runtime_error (" Couldnt find required function!" ); }
75
78
@@ -79,6 +82,7 @@ namespace matplotlibcpp {
79
82
|| !PyFunction_Check (s_python_function_plot)
80
83
|| !PyFunction_Check (s_python_function_legend)
81
84
|| !PyFunction_Check (s_python_function_xlim)
85
+ || !PyFunction_Check (s_python_function_title)
82
86
|| !PyFunction_Check (s_python_function_ylim))
83
87
{ throw std::runtime_error (" Python object is unexpectedly not a PyFunction." ); }
84
88
@@ -244,6 +248,21 @@ namespace matplotlibcpp {
244
248
Py_DECREF (res);
245
249
}
246
250
251
+ inline void title (const std::string &titlestr)
252
+ {
253
+ PyObject* pytitlestr = PyString_FromString (titlestr.c_str ());
254
+ PyObject* args = PyTuple_New (1 );
255
+ PyTuple_SetItem (args, 0 , pytitlestr);
256
+
257
+ PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_title ,
258
+ args);
259
+ if (!res) throw std::runtime_error (" Call to title() failed." );
260
+
261
+ // if(pytitlestr) Py_DECREF(pytitlestr);
262
+ // if(args) Py_DECREF(args);
263
+ // if(res) Py_DECREF(res);
264
+ }
265
+
247
266
inline void show ()
248
267
{
249
268
PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_show , detail::_interpreter::get ().s_python_empty_tuple );
0 commit comments