@@ -96,6 +96,7 @@ struct _interpreter {
9696 PyObject *s_python_function_text;
9797 PyObject *s_python_function_suptitle;
9898 PyObject *s_python_function_bar;
99+ PyObject *s_python_function_barh;
99100 PyObject *s_python_function_colorbar;
100101 PyObject *s_python_function_subplots_adjust;
101102
@@ -243,6 +244,7 @@ struct _interpreter {
243244 s_python_function_text = safe_import (pymod, " text" );
244245 s_python_function_suptitle = safe_import (pymod, " suptitle" );
245246 s_python_function_bar = safe_import (pymod," bar" );
247+ s_python_function_barh = safe_import (pymod, " barh" );
246248 s_python_function_colorbar = PyObject_GetAttrString (pymod, " colorbar" );
247249 s_python_function_subplots_adjust = safe_import (pymod," subplots_adjust" );
248250#ifndef WITHOUT_NUMPY
@@ -1010,6 +1012,36 @@ bool bar(const std::vector<Numeric> & y,
10101012 return bar (x, y, ec, ls, lw, keywords);
10111013}
10121014
1015+
1016+ template <typename Numeric>
1017+ bool barh (const std::vector<Numeric> &x, const std::vector<Numeric> &y, std::string ec = " black" , std::string ls = " -" , double lw = 1.0 , const std::map<std::string, std::string> &keywords = { }) {
1018+ PyObject *xarray = detail::get_array (x);
1019+ PyObject *yarray = detail::get_array (y);
1020+
1021+ PyObject *kwargs = PyDict_New ();
1022+
1023+ PyDict_SetItemString (kwargs, " ec" , PyString_FromString (ec.c_str ()));
1024+ PyDict_SetItemString (kwargs, " ls" , PyString_FromString (ls.c_str ()));
1025+ PyDict_SetItemString (kwargs, " lw" , PyFloat_FromDouble (lw));
1026+
1027+ for (std::map<std::string, std::string>::const_iterator it = keywords.begin (); it != keywords.end (); ++it) {
1028+ PyDict_SetItemString (kwargs, it->first .c_str (), PyUnicode_FromString (it->second .c_str ()));
1029+ }
1030+
1031+ PyObject *plot_args = PyTuple_New (2 );
1032+ PyTuple_SetItem (plot_args, 0 , xarray);
1033+ PyTuple_SetItem (plot_args, 1 , yarray);
1034+
1035+ PyObject *res = PyObject_Call (detail::_interpreter::get ().s_python_function_barh , plot_args, kwargs);
1036+
1037+ Py_DECREF (plot_args);
1038+ Py_DECREF (kwargs);
1039+ if (res) Py_DECREF (res);
1040+
1041+ return res;
1042+ }
1043+
1044+
10131045inline bool subplots_adjust (const std::map<std::string, double >& keywords = {})
10141046{
10151047 detail::_interpreter::get ();
0 commit comments