forked from lava/matplotlib-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathannotate.h
More file actions
30 lines (21 loc) · 760 Bytes
/
Copy pathannotate.h
File metadata and controls
30 lines (21 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once
#include "_python.h"
#include "interpreter.h"
namespace matplotlibcpp {
inline bool annotate(std::string annotation, double x, double y)
{
PyObject * xy = PyTuple_New(2);
PyObject * str = PyString_FromString(annotation.c_str());
PyTuple_SetItem(xy,0,PyFloat_FromDouble(x));
PyTuple_SetItem(xy,1,PyFloat_FromDouble(y));
PyObject* kwargs = PyDict_New();
PyDict_SetItemString(kwargs, "xy", xy);
PyObject* args = PyTuple_New(1);
PyTuple_SetItem(args, 0, str);
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_annotate, args, kwargs);
Py_DECREF(args);
Py_DECREF(kwargs);
if(res != nullptr) Py_DECREF(res);
return res != nullptr;
}
} // end namespace matplotlibcpp