8000 Adds axvline to function scope · lava/matplotlib-cpp@1809d7a · GitHub
[go: up one dir, main page]

Skip to content

Commit 1809d7a

Browse files
cdbrkfxrptlava
authored andcommitted
Adds axvline to function scope
1 parent d283d47 commit 1809d7a

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

matplotlibcpp.h

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct _interpreter {
7070
PyObject *s_python_function_ylim;
7171
PyObject *s_python_function_title;
7272
PyObject *s_python_function_axis;
73+
PyObject *s_python_function_axvline;
7374
PyObject *s_python_function_xlabel;
7475
PyObject *s_python_function_ylabel;
7576
PyObject *s_python_function_xticks;
@@ -202,6 +203,7 @@ struct _interpreter {
202203
s_python_function_ylim = safe_import(pymod, "ylim");
203204
s_python_function_title = safe_import(pymod, "title");
204205
s_python_function_axis = safe_import(pymod, "axis");
206+
s_python_function_axvline = safe_import(pymod, "axvline");
205207
s_python_function_xlabel = safe_import(pymod, "xlabel");
206208
s_python_function_ylabel = safe_import(pymod, "ylabel");
207209
s_python_function_xticks = safe_import(pymod, "xticks");
@@ -1411,21 +1413,21 @@ inline void tick_params(const std::map<std::string, std::string>& keywords, cons
14111413
PyObject* args;
14121414
args = PyTuple_New(1);
14131415
PyTuple_SetItem(args, 0, PyString_FromString(axis.c_str()));
1414-
1416+
14151417
// construct keyword args
14161418
PyObject* kwargs = PyDict_New();
14171419
for (std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
14181420
{
14191421
PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
14201422
}
1421-
1422-
1423+
1424+
14231425
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_tick_params, args, kwargs);
1424-
1426+
14251427
Py_DECREF(args);
14261428
Py_DECREF(kwargs);
14271429
if (!res) throw std::runtime_error("Call to tick_params() failed");
1428-
1430+
14291431
Py_DECREF(res);
14301432
}
14311433

@@ -1520,6 +1522,29 @@ inline void axis(const std::string &axisstr)
15201522
Py_DECREF(res);
15211523
}
15221524

1525+
void axvline(double x, double ymin = 0., double ymax = 1., const std::map<std::string, std::string>& keywords = std::map<std::string, std::string>())
1526+
{
1527+
// construct positional args
1528+
PyObject* args = PyTuple_New(3);
1529+
PyTuple_SetItem(args, 0, PyFloat_FromDouble(x));
1530+
PyTuple_SetItem(args, 1, PyFloat_FromDouble(ymin));
1531+
PyTuple_SetItem(args, 2, PyFloat_FromDouble(ymax));
1532+
1533+
// construct keyword args
1534+
PyObject* kwargs = PyDict_New();
1535+
for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
1536+
{
1537+
PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
1538+
}
1539+
1540+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_axvline, args, kwargs);
1541+
1542+
Py_DECREF(args);
1543+
Py_DECREF(kwargs);
1544+
1545+
if(res) Py_DECREF(res);
1546+
}
1547+
15231548
inline void xlabel(const std::string &str, const std::map<std::string, std::string> &keywords = {})
15241549
{
15251550
PyObject* pystr = PyString_FromString(str.c_str());

0 commit comments

Comments
 (0)
0