@@ -57,6 +57,7 @@ struct _interpreter {
57
57
PyObject *s_python_function_plot;
58
58
PyObject *s_python_function_quiver;
59
59
PyObject* s_python_function_contour;
60
+ PyObject* s_python_function_contourf;
60
61
PyObject *s_python_function_semilogx;
61
62
PyObject *s_python_function_semilogy;
62
63
PyObject *s_python_function_loglog;
@@ -234,6 +235,7 @@ struct _interpreter {
234
235
s_python_function_plot = safe_import (pymod, " plot" );
235
236
s_python_function_quiver = safe_import (pymod, " quiver" );
236
237
s_python_function_contour = safe_import (pymod, " contour" );
238
+ s_python_function_contourf = safe_import (pymod, " contourf" );
237
239
s_python_function_semilogx = safe_import (pymod, " semilogx" );
238
240
s_python_function_semilogy = safe_import (pymod, " semilogy" );
239
241
s_python_function_loglog = safe_import (pymod, " loglog" );
@@ -625,6 +627,48 @@ void contour(const std::vector<::std::vector<Numeric>> &x,
625
627
if (res) Py_DECREF (res);
626
628
}
627
629
630
+ template <typename Numeric>
631
+ void contourf (const std::vector<::std::vector<Numeric>> &x,
632
+ const std::vector<::std::vector<Numeric>> &y,
633
+ const std::vector<::std::vector<Numeric>> &z,
634
+ const std::map<std::string, std::string> &keywords = {})
635
+ {
636
+ detail::_interpreter::get ();
637
+
638
+ // using numpy arrays
639
+ PyObject *xarray = detail::get_2darray (x);
640
+ PyObject *yarray = detail::get_2darray (y);
641
+ PyObject *zarray = detail::get_2darray (z);
642
+
643
+ // construct positional args
644
+ PyObject *args = PyTuple_New (3 );
645
+ PyTuple_SetItem (args, 0 , xarray);
646
+ PyTuple_SetItem (args, 1 , yarray);
647
+ PyTuple_SetItem (args, 2 , zarray);
648
+
649
+ // Build up the kw args.
650
+ PyObject *kwargs = PyDict_New ();
651
+
652
+ PyObject *python_colormap_coolwarm = PyObject_GetAttrString (
653
+ detail::_interpreter::get ().s_python_colormap , " coolwarm" );
654
+
655
+ PyDict_SetItemString (kwargs, " cmap" , python_colormap_coolwarm);
656
+
657
+ for (std::map<std::string, std::string>::const_iterator it = keywords.begin ();
658
+ it != keywords.end (); ++it) {
659
+ PyDict_SetItemString (kwargs, it->first .c_str (),
660
+ PyString_FromString (it->second .c_str ()));
661
+ }
662
+
663
+ PyObject *res = PyObject_Call (detail::_interpreter::get ().s_python_function_contourf , args, kwargs);
664
+ if (!res)
665
+ throw std::runtime_error (" failed contourf" );
666
+
667
+ Py_DECREF (args);
668
+ Py_DECREF (kwargs);
669
+ if (res) Py_DECREF (res);
670
+ }
671
+
628
672
template <typename Numeric>
629
673
void spy (const std::vector<::std::vector<Numeric>> &x,
630
674
const double markersize = -1 , // -1 for default matplotlib size
0 commit comments