From 5079921c0ca287cd5d5ef1d3658d845f985091c1 Mon Sep 17 00:00:00 2001 From: Tako Hisada Date: Sun, 14 Jun 2020 21:38:22 +0000 Subject: [PATCH] feat: Add keyword argument support to legend() --- matplotlibcpp.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/matplotlibcpp.h b/matplotlibcpp.h index ea2e4fb2..c3d3d2a8 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -1491,6 +1491,24 @@ inline void legend() Py_DECREF(res); } +inline void legend(const std::map& keywords) +{ + detail::_interpreter::get(); + + // construct keyword args + PyObject* kwargs = PyDict_New(); + for(std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) + { + PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str())); + } + + PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_legend, detail::_interpreter::get().s_python_empty_tuple, kwargs); + if(!res) throw std::runtime_error("Call to legend() failed."); + + Py_DECREF(kwargs); + Py_DECREF(res); +} + template void ylim(Numeric left, Numeric right) {