@@ -31,6 +31,7 @@ namespace matplotlibcpp {
31
31
PyObject *s_python_function_ylabel;
32
32
PyObject *s_python_function_grid;
33
33
PyObject *s_python_empty_tuple;
34
+ PyObject *s_python_function_annotate;
34
35
35
36
/* For now, _interpreter is implemented as a singleton since its currently not possible to have
36
37
multiple independent embedded python interpreters without patching the python source code
@@ -75,12 +76,13 @@ namespace matplotlibcpp {
75
76
s_python_function_grid = PyObject_GetAttrString (pymod, " grid" );
76
77
s_python_function_xlim = PyObject_GetAttrString (pymod, " xlim" );
77
78
s_python_function_save = PyObject_GetAttrString (pylabmod, " savefig" );
79
+ s_python_function_annotate = PyObject_GetAttrString (pymod," annotate" );
78
80
79
81
if ( !s_python_function_show
80
82
|| !s_python_function_figure
81
83
|| !s_python_function_plot
82
84
|| !s_python_function_subplot
83
- || !s_python_function_legend
85
+ || !s_python_function_legend
84
86
|| !s_python_function_ylim
85
87
|| !s_python_function_title
86
88
|| !s_python_function_axis
@@ -89,14 +91,16 @@ namespace matplotlibcpp {
89
91
|| !s_python_function_grid
90
92
|| !s_python_function_xlim
91
93
|| !s_python_function_save
94
+ || !s_python_function_annotate
92
95
)
93
96
{ throw std::runtime_error (" Couldn't find required function!" ); }
94
97
95
98
if ( !PyFunction_Check (s_python_function_show)
96
99
|| !PyFunction_Check (s_python_function_figure)
97
100
|| !PyFunction_Check (s_python_function_plot)
98
101
|| !PyFunction_Check (s_python_function_subplot)
99
- || !PyFunction_Check (s_python_function_legend)
102
+ || !PyFunction_Check (s_python_function_legend)
103
+ || !PyFunction_Check (s_python_function_annotate)
100
104
|| !PyFunction_Check (s_python_function_ylim)
101
105
|| !PyFunction_Check (s_python_function_title)
102
106
|| !PyFunction_Check (s_python_function_axis)
@@ -116,6 +120,31 @@ namespace matplotlibcpp {
116
120
}
117
121
};
118
122
}
123
+
124
+ bool annotate (std::string annotation, double x, double y)
125
+ {
126
+ PyObject * xy = PyTuple_New (2 );
127
+ PyObject * str = PyString_FromString (annotation.c_str ());
128
+
129
+ PyTuple_SetItem (xy,0 ,PyFloat_FromDouble (x));
130
+ PyTuple_SetItem (xy,1 ,PyFloat_FromDouble (y));
131
+
132
+ PyObject* kwargs = PyDict_New ();
133
+ PyDict_SetItemString (kwargs, " xy" , xy);
134
+
135
+ PyObject* args = PyTuple_New (1 );
136
+ PyTuple_SetItem (args, 0 , str);
137
+
138
+ PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_annotate , args, kwargs);
139
+
140
+ Py_DECREF (xy);
141
+ Py_DECREF (args);
142
+ Py_DECREF (kwargs);
143
+
144
+ if (res) Py_DECREF (res);
145
+
146
+ return res;
147
+ }
119
148
120
149
template <typename Numeric>
121
150
bool plot (const std::vector<Numeric> &x, const std::vector<Numeric> &y, const std::map<std::string, std::string>& keywords)
0 commit comments