| 1252 | |
| 1253 | template<typename NumericX, typename NumericY> |
| 1254 | bool errorbar(const std::vector<NumericX> &x, const std::vector<NumericY> &y, const std::vector<NumericX> &yerr, const std::map<std::string, std::string> &keywords = {}) |
| 1255 | { |
| 1256 | assert(x.size() == y.size()); |
| 1257 | |
| 1258 | detail::_interpreter::get(); |
| 1259 | |
| 1260 | PyObject* xarray = detail::get_array(x); |
| 1261 | PyObject* yarray = detail::get_array(y); |
| 1262 | PyObject* yerrarray = detail::get_array(yerr); |
| 1263 | |
| 1264 | // construct keyword args |
| 1265 | PyObject* kwargs = PyDict_New(); |
| 1266 | for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it) |
| 1267 | { |
| 1268 | PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str())); |
| 1269 | } |
| 1270 | |
| 1271 | PyDict_SetItemString(kwargs, "yerr", yerrarray); |
| 1272 | |
| 1273 | PyObject *plot_args = PyTuple_New(2); |
| 1274 | PyTuple_SetItem(plot_args, 0, xarray); |
| 1275 | PyTuple_SetItem(plot_args, 1, yarray); |
| 1276 | |
| 1277 | PyObject *res = PyObject_Call(detail::_interpreter::get().s_python_function_errorbar, plot_args, kwargs); |
| 1278 | |
| 1279 | Py_DECREF(kwargs); |
| 1280 | Py_DECREF(plot_args); |
| 1281 | |
| 1282 | if (res) |
| 1283 | Py_DECREF(res); |
| 1284 | else |
| 1285 | throw std::runtime_error("Call to errorbar() failed."); |
| 1286 | |
| 1287 | return res; |
| 1288 | } |
| 1289 | |
| 1290 | template<typename Numeric> |
| 1291 | bool named_plot(const std::string& name, const std::vector<Numeric>& y, const std::string& format = "") |