forked from lava/matplotlib-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrorbar.h
More file actions
39 lines (28 loc) · 1.05 KB
/
Copy patherrorbar.h
File metadata and controls
39 lines (28 loc) · 1.05 KB
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
31
32
33
34
35
36
37
38
39
#pragma once
#include "_python.h"
#include "interpreter.h"
#include "helpers.h"
namespace matplotlibcpp {
template<typename NumericX, typename NumericY>
bool errorbar(const std::vector<NumericX> &x, const std::vector<NumericY> &y, const std::vector<NumericX> &yerr, const std::string &s = "")
{
assert(x.size() == y.size());
PyObject* xarray = get_array(x);
PyObject* yarray = get_array(y);
PyObject* yerrarray = get_array(yerr);
PyObject *kwargs = PyDict_New();
PyDict_SetItemString(kwargs, "yerr", yerrarray);
PyObject *pystring = PyString_FromString(s.c_str());
PyObject *plot_args = PyTuple_New(2);
PyTuple_SetItem(plot_args, 0, xarray);
PyTuple_SetItem(plot_args, 1, yarray);
PyObject *res = PyObject_Call(detail::_interpreter::get().s_python_function_errorbar, plot_args, kwargs);
Py_DECREF(kwargs);
Py_DECREF(plot_args);
if (res != nullptr)
Py_DECREF(res);
else
throw std::runtime_error("Call to errorbar() failed.");
return res != nullptr;
}
} // end namespace matplotlibcpp