Skip to content

Commit f249494

Browse files
committed
feat: add kwargs for grid function
1 parent d306430 commit f249494

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

matplotlibcpp.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#pragma once
2+
#ifndef __MATPLOTLIBCPP__H__
3+
#define __MATPLOTLIBCPP__H__
24

35
// Python headers must be included before any system headers, since
46
// they define _POSIX_C_SOURCE
@@ -2499,7 +2501,7 @@ inline void set_zlabel(const std::string &str, const std::map<std::string, std::
24992501
if (res) Py_DECREF(res);
25002502
}
25012503

2502-
inline void grid(bool flag)
2504+
inline void grid(bool flag, const std::map<std::string, std::string>& keywords = std::map<std::string, std::string>())
25032505
{
25042506
detail::_interpreter::get();
25052507

@@ -2509,10 +2511,16 @@ inline void grid(bool flag)
25092511
PyObject* args = PyTuple_New(1);
25102512
PyTuple_SetItem(args, 0, pyflag);
25112513

2512-
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_grid, args);
2514+
PyObject* kwargs = PyDict_New();
2515+
for (auto it = keywords.begin(); it != keywords.end(); ++it) {
2516+
PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
2517+
}
2518+
2519+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_grid, args, kwargs);
25132520
if(!res) throw std::runtime_error("Call to grid() failed.");
25142521

25152522
Py_DECREF(args);
2523+
Py_DECREF(kwargs);
25162524
Py_DECREF(res);
25172525
}
25182526

@@ -2632,7 +2640,7 @@ inline void rcparams(const std::map<std::string, std::string>& keywords = {}) {
26322640
PyDict_SetItemString(kwargs, it->first.c_str(), PyLong_FromLong(std::stoi(it->second.c_str())));
26332641
else PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
26342642
}
2635-
2643+
26362644
PyObject * update = PyObject_GetAttrString(detail::_interpreter::get().s_python_function_rcparams, "update");
26372645
PyObject * res = PyObject_Call(update, args, kwargs);
26382646
if(!res) throw std::runtime_error("Call to rcParams.update() failed.");
@@ -2961,3 +2969,5 @@ class Plot
29612969
};
29622970

29632971
} // end namespace matplotlibcpp
2972+
2973+
#endif //!__MATPLOTLIBCPP__H__

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