@@ -675,35 +675,56 @@ bool scatter(const std::vector<NumericX>& x,
675
675
return res;
676
676
}
677
677
678
- template < typename Numeric>
679
- bool bar (const std::vector<Numeric>& y, std::string ec = " black" , std::string ls = " -" , double lw = 1.0 ,
680
- __attribute__ ((unused)) const std::map<std::string, std::string>& keywords = {})
681
- {
682
- PyObject* yarray = get_array (y);
683
-
684
- std::vector<int > x;
685
- for (std::size_t i = 0 ; i < y.size (); i++)
686
- x.push_back (i);
678
+ template <typename Numeric>
679
+ bool bar (const std::vector<Numeric> & x,
680
+ const std::vector<Numeric> & y,
681
+ std::string ec = " black" ,
682
+ std::string ls = " -" ,
683
+ double lw = 1.0 ,
684
+ const std::map<std::string, std::string> & keywords = {}) {
685
+ PyObject * xarray = get_array (x);
686
+ PyObject * yarray = get_array (y);
687
+
688
+ PyObject * kwargs = PyDict_New ();
689
+
690
+ PyDict_SetItemString (kwargs, " ec" , PyString_FromString (ec.c_str ()));
691
+ PyDict_SetItemString (kwargs, " ls" , PyString_FromString (ls.c_str ()));
692
+ PyDict_SetItemString (kwargs, " lw" , PyFloat_FromDouble (lw));
693
+
694
+ for (std::map<std::string, std::string>::const_iterator it =
695
+ keywords.begin ();
696
+ it != keywords.end ();
697
+ ++it) {
698
+ PyDict_SetItemString (
699
+ kwargs, it->first .c_str (), PyUnicode_FromString (it->second .c_str ()));
700
+ }
687
701
688
- PyObject* xarray = get_array (x);
702
+ PyObject * plot_args = PyTuple_New (2 );
703
+ PyTuple_SetItem (plot_args, 0 , xarray);
704
+ PyTuple_SetItem (plot_args, 1 , yarray);
689
705
690
- PyObject* kwargs = PyDict_New ();
706
+ PyObject * res = PyObject_Call (
707
+ detail::_interpreter::get ().s_python_function_bar , plot_args, kwargs);
691
708
692
- PyDict_SetItemString (kwargs, " ec " , PyString_FromString (ec. c_str ()) );
693
- PyDict_SetItemString (kwargs, " ls " , PyString_FromString (ls. c_str ()) );
694
- PyDict_SetItemString (kwargs, " lw " , PyFloat_FromDouble (lw) );
709
+ Py_DECREF (plot_args );
710
+ Py_DECREF (kwargs);
711
+ if (res) Py_DECREF (res );
695
712
696
- PyObject* plot_args = PyTuple_New (2 );
697
- PyTuple_SetItem (plot_args, 0 , xarray);
698
- PyTuple_SetItem (plot_args, 1 , yarray);
713
+ return res;
714
+ }
699
715
700
- PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_bar , plot_args, kwargs);
716
+ template <typename Numeric>
717
+ bool bar (const std::vector<Numeric> & y,
718
+ std::string ec = " black" ,
719
+ std::string ls = " -" ,
720
+ double lw = 1.0 ,
721
+ const std::map<std::string, std::string> & keywords = {}) {
722
+ using T = typename std::remove_reference<decltype (y)>::type::value_type;
701
723
702
- Py_DECREF (plot_args);
703
- Py_DECREF (kwargs);
704
- if (res) Py_DECREF (res);
724
+ std::vector<T> x;
725
+ for (std::size_t i = 0 ; i < y.size (); i++) { x.push_back (i); }
705
726
706
- return res ;
727
+ return bar (x, y, ec, ls, lw, keywords) ;
707
728
}
708
729
709
730
inline bool subplots_adjust (const std::map<std::string, double >& keywords = {})
0 commit comments