@@ -39,6 +39,7 @@ struct _interpreter {
3939 PyObject *s_python_function_semilogx;
4040 PyObject *s_python_function_semilogy;
4141 PyObject *s_python_function_loglog;
42+ PyObject *s_python_function_fill;
4243 PyObject *s_python_function_fill_between;
4344 PyObject *s_python_function_hist;
4445 PyObject *s_python_function_scatter;
@@ -155,6 +156,7 @@ struct _interpreter {
155156 s_python_function_semilogx = PyObject_GetAttrString (pymod, " semilogx" );
156157 s_python_function_semilogy = PyObject_GetAttrString (pymod, " semilogy" );
157158 s_python_function_loglog = PyObject_GetAttrString (pymod, " loglog" );
159+ s_python_function_fill = PyObject_GetAttrString (pymod, " fill" );
158160 s_python_function_fill_between = PyObject_GetAttrString (pymod, " fill_between" );
159161 s_python_function_hist = PyObject_GetAttrString (pymod," hist" );
160162 s_python_function_scatter = PyObject_GetAttrString (pymod," scatter" );
@@ -194,6 +196,7 @@ struct _interpreter {
194196 || !s_python_function_semilogx
195197 || !s_python_function_semilogy
196198 || !s_python_function_loglog
199+ || !s_python_function_fill
197200 || !s_python_function_fill_between
198201 || !s_python_function_subplot
199202 || !s_python_function_legend
@@ -231,6 +234,7 @@ struct _interpreter {
231234 || !PyFunction_Check (s_python_function_semilogx)
232235 || !PyFunction_Check (s_python_function_semilogy)
233236 || !PyFunction_Check (s_python_function_loglog)
237+ || !PyFunction_Check (s_python_function_fill)
234238 || !PyFunction_Check (s_python_function_fill_between)
235239 || !PyFunction_Check (s_python_function_subplot)
236240 || !PyFunction_Check (s_python_function_legend)
@@ -523,6 +527,36 @@ bool stem(const std::vector<Numeric> &x, const std::vector<Numeric> &y, const st
523527 return res;
524528}
525529
530+ template < typename Numeric >
531+ bool fill (const std::vector<Numeric>& x, const std::vector<Numeric>& y, const std::map<std::string, std::string>& keywords)
532+ {
533+ assert (x.size () == y.size ());
534+
535+ // using numpy arrays
536+ PyObject* xarray = get_array (x);
537+ PyObject* yarray = get_array (y);
538+
539+ // construct positional args
540+ PyObject* args = PyTuple_New (2 );
541+ PyTuple_SetItem (args, 0 , xarray);
542+ PyTuple_SetItem (args, 1 , yarray);
543+
544+ // construct keyword args
545+ PyObject* kwargs = PyDict_New ();
546+ for (auto it = keywords.begin (); it != keywords.end (); ++it) {
547+ PyDict_SetItemString (kwargs, it->first .c_str (), PyUnicode_FromString (it->second .c_str ()));
548+ }
549+
550+ PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_fill , args, kwargs);
551+
552+ Py_DECREF (args);
553+ Py_DECREF (kwargs);
554+
555+ if (res) Py_DECREF (res);
556+
557+ return res;
558+ }
559+
526560template < typename Numeric >
527561bool 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)
528562{
@@ -542,8 +576,7 @@ bool fill_between(const std::vector<Numeric>& x, const std::vector<Numeric>& y1,
542576
543577 // construct keyword args
544578 PyObject* kwargs = PyDict_New ();
545- for (std::map<std::string, std::string>::const_iterator it = keywords.begin (); it != keywords.end (); ++it)
546- {
579+ for (std::map<std::string, std::string>::const_iterator it = keywords.begin (); it != keywords.end (); ++it) {
547580 PyDict_SetItemString (kwargs, it->first .c_str (), PyUnicode_FromString (it->second .c_str ()));
548581 }
549582
0 commit comments