| 403 | /// See: https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.plot.html |
| 404 | template<typename Numeric> |
| 405 | bool plot(const std::vector<Numeric> &x, const std::vector<Numeric> &y, const std::map<std::string, std::string>& keywords) |
| 406 | { |
| 407 | assert(x.size() == y.size()); |
| 408 | |
| 409 | detail::_interpreter::get(); |
| 410 | |
| 411 | // using numpy arrays |
| 412 | PyObject* xarray = detail::get_array(x); |
| 413 | PyObject* yarray = detail::get_array(y); |
| 414 | |
| 415 | // construct positional args |
| 416 | PyObject* args = PyTuple_New(2); |
| 417 | PyTuple_SetItem(args, 0, xarray); |
| 418 | PyTuple_SetItem(args, 1, yarray); |
| 419 | |
| 420 | // construct keyword args |
| 421 | PyObject* kwargs = PyDict_New(); |
| 422 | for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it) |
| 423 | { |
| 424 | PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str())); |
| 425 | } |
| 426 | |
| 427 | PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_plot, args, kwargs); |
| 428 | |
| 429 | Py_DECREF(args); |
| 430 | Py_DECREF(kwargs); |
| 431 | if(res) Py_DECREF(res); |
| 432 | |
| 433 | return res; |
| 434 | } |
| 435 | |
| 436 | // TODO - it should be possible to make this work by implementing |
| 437 | // a non-numpy alternative for `detail::get_2darray()`. |
nothing calls this directly
no test coverage detected