Skip to content

Commit ec37453

Browse files
CryorisBenno Evers
authored andcommitted
add axhline
1 parent 1875696 commit ec37453

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

matplotlibcpp.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct _interpreter {
7575
PyObject *s_python_function_ylim;
7676
PyObject *s_python_function_title;
7777
PyObject *s_python_function_axis;
78+
PyObject *s_python_function_axhline;
7879
PyObject *s_python_function_axvline;
7980
PyObject *s_python_function_axvspan;
8081
PyObject *s_python_function_xlabel;
@@ -247,6 +248,7 @@ struct _interpreter {
247248
s_python_function_ylim = safe_import(pymod, "ylim");
248249
s_python_function_title = safe_import(pymod, "title");
249250
s_python_function_axis = safe_import(pymod, "axis");
251+
s_python_function_axhline = safe_import(pymod, "axhline");
250252
s_python_function_axvline = safe_import(pymod, "axvline");
251253
s_python_function_axvspan = safe_import(pymod, "axvspan");
252254
s_python_function_xlabel = safe_import(pymod, "xlabel");
@@ -2238,6 +2240,31 @@ inline void axis(const std::string &axisstr)
22382240
Py_DECREF(res);
22392241
}
22402242

2243+
inline void axhline(double y, double xmin = 0., double xmax = 1., const std::map<std::string, std::string>& keywords = std::map<std::string, std::string>())
2244+
{
2245+
detail::_interpreter::get();
2246+
2247+
// construct positional args
2248+
PyObject* args = PyTuple_New(3);
2249+
PyTuple_SetItem(args, 0, PyFloat_FromDouble(y));
2250+
PyTuple_SetItem(args, 1, PyFloat_FromDouble(xmin));
2251+
PyTuple_SetItem(args, 2, PyFloat_FromDouble(xmax));
2252+
2253+
// construct keyword args
2254+
PyObject* kwargs = PyDict_New();
2255+
for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
2256+
{
2257+
PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
2258+
}
2259+
2260+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_axhline, args, kwargs);
2261+
2262+
Py_DECREF(args);
2263+
Py_DECREF(kwargs);
2264+
2265+
if(res) Py_DECREF(res);
2266+
}
2267+
22412268
inline void axvline(double x, double ymin = 0., double ymax = 1., const std::map<std::string, std::string>& keywords = std::map<std::string, std::string>())
22422269
{
22432270
detail::_interpreter::get();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy