@@ -32,6 +32,7 @@ namespace matplotlibcpp {
32
32
PyObject *s_python_function_save;
33
33
PyObject *s_python_function_figure;
34
34
PyObject *s_python_function_plot;
35
+ PyObject *s_python_function_fill_between;
35
36
PyObject *s_python_function_hist;
36
37
PyObject *s_python_function_subplot;
37
38
PyObject *s_python_function_legend;
@@ -85,6 +86,7 @@ namespace matplotlibcpp {
85
86
s_python_function_show = PyObject_GetAttrString (pymod, " show" );
86
87
s_python_function_figure = PyObject_GetAttrString (pymod, " figure" );
87
88
s_python_function_plot = PyObject_GetAttrString (pymod, " plot" );
89
+ s_python_function_fill_between = PyObject_GetAttrString (pymod, " fill_between" );
88
90
s_python_function_hist = PyObject_GetAttrString (pymod," hist" );
89
91
s_python_function_subplot = PyObject_GetAttrString (pymod, " subplot" );
90
92
s_python_function_legend = PyObject_GetAttrString (pymod, " legend" );
@@ -103,6 +105,7 @@ namespace matplotlibcpp {
103
105
if ( !s_python_function_show
104
106
|| !s_python_function_figure
105
107
|| !s_python_function_plot
108
+ || !s_python_function_fill_between
106
109
|| !s_python_function_subplot
107
110
|| !s_python_function_legend
108
111
|| !s_python_function_ylim
@@ -121,6 +124,7 @@ namespace matplotlibcpp {
121
124
if ( !PyFunction_Check (s_python_function_show)
122
125
|| !PyFunction_Check (s_python_function_figure)
123
126
|| !PyFunction_Check (s_python_function_plot)
127
+ || !PyFunction_Check (s_python_function_fill_between)
124
128
|| !PyFunction_Check (s_python_function_subplot)
125
129
|| !PyFunction_Check (s_python_function_legend)
126
130
|| !PyFunction_Check (s_python_function_annotate)
@@ -204,6 +208,45 @@ namespace matplotlibcpp {
204
208
return res;
205
209
}
206
210
211
+ template < typename Numeric >
212
+ bool fill_between (const std::vector<Numeric>& x, const std::vector<Numeric>& y1, const std::vector<Numeric>& y2, const std::map<std::string, std::string>& keywords)
213
+ {
214
+ assert (x.size () == y1 .size ());
215
+ assert (x.size () == y2.size ());
216
+
217
+ // using python lists
218
+ PyObject* xlist = PyList_New (x.size ());
219
+ PyObject* y1list = PyList_New (y1 .size ());
220
+ PyObject* y2list = PyList_New (y2.size ());
221
+
222
+ for (size_t i = 0 ; i < x.size (); ++i) {
223
+ PyList_SetItem (xlist, i, PyFloat_FromDouble (x.at (i)));
224
+ PyList_SetItem (y1list, i, PyFloat_FromDouble (y1 .at (i)));
225
+ PyList_SetItem (y2list, i, PyFloat_FromDouble (y2.at (i)));
226
+ }
227
+
228
+ // construct positional args
229
+ PyObject* args = PyTuple_New (3 );
230
+ PyTuple_SetItem (args, 0 , xlist);
231
+ PyTuple_SetItem (args, 1 , y1list);
232
+ PyTuple_SetItem (args, 2 , y2list);
233
+
234
+ // construct keyword args
235
+ PyObject* kwargs = PyDict_New ();
236
+ for (std::map<std::string, std::string>::const_iterator it = keywords.begin (); it != keywords.end (); ++it)
237
+ {
238
+ PyDict_SetItemString (kwargs, it->first .c_str (), PyUnicode_FromString (it->second .c_str ()));
239
+ }
240
+
241
+ PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_fill_between , args, kwargs);
242
+
243
+ Py_DECREF (args);
244
+ Py_DECREF (kwargs);
245
+ if (res) Py_DECREF (res);
246
+
247
+ return res;
248
+ }
249
+
207
250
template < typename Numeric>
208
251
bool hist (const std::vector<Numeric>& y, long bins=10 ,std::string color=" b" , double alpha=1.0 )
209
252
{
0 commit comments