@@ -96,6 +96,7 @@ struct _interpreter {
96
96
PyObject *s_python_function_text;
97
97
PyObject *s_python_function_suptitle;
98
98
PyObject *s_python_function_bar;
99
+ PyObject *s_python_function_barh;
99
100
PyObject *s_python_function_colorbar;
100
101
PyObject *s_python_function_subplots_adjust;
101
102
@@ -243,6 +244,7 @@ struct _interpreter {
243
244
s_python_function_text = safe_import (pymod, " text" );
244
245
s_python_function_suptitle = safe_import (pymod, " suptitle" );
245
246
s_python_function_bar = safe_import (pymod," bar" );
247
+ s_python_function_barh = safe_import (pymod, " barh" );
246
248
s_python_function_colorbar = PyObject_GetAttrString (pymod, " colorbar" );
247
249
s_python_function_subplots_adjust = safe_import (pymod," subplots_adjust" );
248
250
#ifndef WITHOUT_NUMPY
@@ -1010,6 +1012,36 @@ bool bar(const std::vector<Numeric> & y,
1010
1012
return bar (x, y, ec, ls, lw, keywords);
1011
1013
}
1012
1014
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
+
1013
1045
inline bool subplots_adjust (const std::map<std::string, double >& keywords = {})
1014
1046
{
1015
1047
detail::_interpreter::get ();
0 commit comments