@@ -316,7 +316,8 @@ struct _interpreter {
316
316
// must be called before the first regular call to matplotlib to have any effect
317
317
inline void backend (const std::string &name) { detail::s_backend = name; }
318
318
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 = {}) {
320
321
detail::_interpreter::get ();
321
322
322
323
PyObject *xy = PyTuple_New (2 );
@@ -328,6 +329,11 @@ inline bool annotate(std::string annotation, double x, double y) {
328
329
PyObject *kwargs = PyDict_New ();
329
330
PyDict_SetItemString (kwargs, " xy" , xy);
330
331
332
+ for (auto const &item : keywords) {
333
+ PyDict_SetItemString (kwargs, item.first .c_str (),
334
+ PyString_FromString (item.second .c_str ()));
335
+ }
336
+
331
337
PyObject *args = PyTuple_New (1 );
332
338
PyTuple_SetItem (args, 0 , str);
333
339
@@ -1300,16 +1306,23 @@ bool stem(const std::vector<Numeric> &y, const std::string &format = "") {
1300
1306
}
1301
1307
1302
1308
template <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 = {}) {
1304
1311
detail::_interpreter::get ();
1305
1312
1306
1313
PyObject *args = PyTuple_New (3 );
1307
1314
PyTuple_SetItem (args, 0 , PyFloat_FromDouble (x));
1308
1315
PyTuple_SetItem (args, 1 , PyFloat_FromDouble (y));
1309
1316
PyTuple_SetItem (args, 2 , PyString_FromString (s.c_str ()));
1310
1317
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);
1313
1326
if (!res)
1314
1327
throw std::runtime_error (" Call to text() failed." );
1315
1328
0 commit comments