@@ -316,7 +316,8 @@ struct _interpreter {
316316// must be called before the first regular call to matplotlib to have any effect
317317inline void backend (const std::string &name) { detail::s_backend = name; }
318318
319- inline bool annotate (std::string annotation, double x, double y) {
319+ inline bool annotate (std::string annotation, double x, double y,
320+ const std::map<std::string, std::string> &keywords = {}) {
320321 detail::_interpreter::get ();
321322
322323 PyObject *xy = PyTuple_New (2 );
@@ -328,6 +329,11 @@ inline bool annotate(std::string annotation, double x, double y) {
328329 PyObject *kwargs = PyDict_New ();
329330 PyDict_SetItemString (kwargs, " xy" , xy);
330331
332+ for (auto const &item : keywords) {
333+ PyDict_SetItemString (kwargs, item.first .c_str (),
334+ PyString_FromString (item.second .c_str ()));
335+ }
336+
331337 PyObject *args = PyTuple_New (1 );
332338 PyTuple_SetItem (args, 0 , str);
333339
@@ -1300,16 +1306,23 @@ bool stem(const std::vector<Numeric> &y, const std::string &format = "") {
13001306}
13011307
13021308template <typename Numeric>
1303- void text (Numeric x, Numeric y, const std::string &s = " " ) {
1309+ void text (Numeric x, Numeric y, const std::string &s = " " ,
1310+ const std::map<std::string, std::string> &keywords = {}) {
13041311 detail::_interpreter::get ();
13051312
13061313 PyObject *args = PyTuple_New (3 );
13071314 PyTuple_SetItem (args, 0 , PyFloat_FromDouble (x));
13081315 PyTuple_SetItem (args, 1 , PyFloat_FromDouble (y));
13091316 PyTuple_SetItem (args, 2 , PyString_FromString (s.c_str ()));
13101317
1311- PyObject *res = PyObject_CallObject (
1312- detail::_interpreter::get ().s_python_function_text , args);
1318+ PyObject *kwargs = PyDict_New ();
1319+ for (auto const &item : keywords) {
1320+ PyDict_SetItemString (kwargs, item.first .c_str (),
1321+ PyString_FromString (item.second .c_str ()));
1322+ }
1323+
1324+ PyObject *res = PyObject_Call (
1325+ detail::_interpreter::get ().s_python_function_text , args, kwargs);
13131326 if (!res)
13141327 throw std::runtime_error (" Call to text() failed." );
13151328
0 commit comments