forked from gmrukwa/matplotlib-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhist.h
More file actions
58 lines (39 loc) · 1.66 KB
/
Copy pathhist.h
File metadata and controls
58 lines (39 loc) · 1.66 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include "_python.h"
#include "interpreter.h"
#include "helpers.h"
namespace matplotlibcpp {
template< typename Numeric>
bool hist(const std::vector<Numeric>& y, long bins=10,std::string color="b", double alpha=1.0)
{
PyObject* yarray = get_array(y);
PyObject* kwargs = PyDict_New();
PyDict_SetItemString(kwargs, "bins", PyLong_FromLong(bins));
PyDict_SetItemString(kwargs, "color", PyString_FromString(color.c_str()));
PyDict_SetItemString(kwargs, "alpha", PyFloat_FromDouble(alpha));
PyObject* plot_args = PyTuple_New(1);
PyTuple_SetItem(plot_args, 0, yarray);
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_hist, plot_args, kwargs);
Py_DECREF(plot_args);
Py_DECREF(kwargs);
if(res != nullptr) Py_DECREF(res);
return res != nullptr;
}
template< typename Numeric>
bool named_hist(std::string label,const std::vector<Numeric>& y, long bins=10, std::string color="b", double alpha=1.0)
{
PyObject* yarray = get_array(y);
PyObject* kwargs = PyDict_New();
PyDict_SetItemString(kwargs, "label", PyString_FromString(label.c_str()));
PyDict_SetItemString(kwargs, "bins", PyLong_FromLong(bins));
PyDict_SetItemString(kwargs, "color", PyString_FromString(color.c_str()));
PyDict_SetItemString(kwargs, "alpha", PyFloat_FromDouble(alpha));
PyObject* plot_args = PyTuple_New(1);
PyTuple_SetItem(plot_args, 0, yarray);
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_hist, plot_args, kwargs);
Py_DECREF(plot_args);
Py_DECREF(kwargs);
if(res != nullptr) Py_DECREF(res);
return res != nullptr;
}
} // end namespace matplotlibcpp