Skip to content

Commit a8c7d5b

Browse files
committed
kwargs added to text function
1 parent af2eda8 commit a8c7d5b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

matplotlibcpp.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,18 +1887,26 @@ bool stem(const std::vector<Numeric>& y, const std::string& format = "") {
18871887
}
18881888

18891889
template <typename Numeric>
1890-
void text(Numeric x, Numeric y, const std::string& s = "") {
1890+
void text(Numeric x, Numeric y, const std::string& s,
1891+
const std::map<std::string, std::string>& keywords = {}) {
18911892
detail::_interpreter::get();
18921893

18931894
PyObject* args = PyTuple_New(3);
18941895
PyTuple_SetItem(args, 0, PyFloat_FromDouble(x));
18951896
PyTuple_SetItem(args, 1, PyFloat_FromDouble(y));
18961897
PyTuple_SetItem(args, 2, PyString_FromString(s.c_str()));
18971898

1898-
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_text, args);
1899+
PyObject* kwargs = PyDict_New();
1900+
for (std::map<std::string, std::string>::const_iterator it = keywords.begin();
1901+
it != keywords.end(); ++it) {
1902+
PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
1903+
}
1904+
1905+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_text, args, kwargs);
18991906
if (!res) throw std::runtime_error("Call to text() failed.");
19001907

19011908
Py_DECREF(args);
1909+
Py_DECREF(kwargs);
19021910
Py_DECREF(res);
19031911
}
19041912

0 commit comments

Comments
 (0)