@@ -32,6 +32,7 @@ namespace matplotlibcpp {
32
32
PyObject *s_python_function_xlabel;
33
33
PyObject *s_python_function_ylabel;
34
34
PyObject *s_python_function_grid;
35
+ PyObject *s_python_function_clf;
35
36
PyObject *s_python_empty_tuple;
36
37
PyObject *s_python_function_annotate;
37
38
@@ -79,6 +80,7 @@ namespace matplotlibcpp {
79
80
s_python_function_xlim = PyObject_GetAttrString (pymod, " xlim" );
80
81
s_python_function_save = PyObject_GetAttrString (pylabmod, " savefig" );
81
82
s_python_function_annotate = PyObject_GetAttrString (pymod, " annotate" );
83
+ s_python_function_clf = PyObject_GetAttrString (pymod, " clf" );
82
84
83
85
if (!s_python_function_show
84
86
|| !s_python_function_figure
@@ -93,6 +95,7 @@ namespace matplotlibcpp {
93
95
|| !s_python_function_grid
94
96
|| !s_python_function_xlim
95
97
|| !s_python_function_save
98
+ || !s_python_function_clf
96
99
|| !s_python_function_annotate
97
100
) { throw std::runtime_error (" Couldn't find required function!" ); }
98
101
@@ -110,6 +113,7 @@ namespace matplotlibcpp {
110
113
|| !PyFunction_Check (s_python_function_grid)
111
114
|| !PyFunction_Check (s_python_function_xlim)
112
115
|| !PyFunction_Check (s_python_function_save)
116
+ || !PyFunction_Check (s_python_function_clf)
113
117
) { throw std::runtime_error (" Python object is unexpectedly not a PyFunction." ); }
114
118
115
119
s_python_empty_tuple = PyTuple_New (0 );
@@ -163,9 +167,6 @@ namespace matplotlibcpp {
163
167
PyTuple_SetItem (args, 0 , xlist);
164
168
PyTuple_SetItem (args, 1 , ylist);
165
169
166
- Py_DECREF (xlist);
167
- Py_DECREF (ylist);
168
-
169
170
// construct keyword args
170
171
PyObject *kwargs = PyDict_New ();
171
172
for (std::map<std::string, std::string>::const_iterator it = keywords.begin (); it != keywords.end (); ++it) {
@@ -492,11 +493,18 @@ namespace matplotlibcpp {
492
493
PyObject *res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_save , args);
493
494
if (!res) throw std::runtime_error (" Call to save() failed." );
494
495
495
- Py_DECREF (pyfilename);
496
496
Py_DECREF (args);
497
497
Py_DECREF (res);
498
498
}
499
499
500
+ inline void clf () {
501
+ PyObject *res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_clf ,
502
+ detail::_interpreter::get ().s_python_empty_tuple );
503
+ if (!res) throw std::runtime_error (" Call to clf() failed." );
504
+
505
+ Py_DECREF (res);
506
+ }
507
+
500
508
#if __cplusplus > 199711L
501
509
// C++11-exclusive content starts here (variadic plot() and initializer list support)
502
510
@@ -577,8 +585,6 @@ namespace matplotlibcpp {
577
585
578
586
PyObject *res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_plot , plot_args);
579
587
580
- Py_DECREF (xlist);
581
- Py_DECREF (ylist);
582
588
Py_DECREF (plot_args);
583
589
if (res) Py_DECREF (res);
584
590
0 commit comments