1
1
#pragma once
2
+ #ifndef __MATPLOTLIBCPP__H__
3
+ #define __MATPLOTLIBCPP__H__
2
4
3
5
// Python headers must be included before any system headers, since
4
6
// they define _POSIX_C_SOURCE
@@ -2499,7 +2501,7 @@ inline void set_zlabel(const std::string &str, const std::map<std::string, std::
2499
2501
if (res) Py_DECREF (res);
2500
2502
}
2501
2503
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>() )
2503
2505
{
2504
2506
detail::_interpreter::get ();
2505
2507
@@ -2509,10 +2511,16 @@ inline void grid(bool flag)
2509
2511
PyObject* args = PyTuple_New (1 );
2510
2512
PyTuple_SetItem (args, 0 , pyflag);
2511
2513
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);
2513
2520
if (!res) throw std::runtime_error (" Call to grid() failed." );
2514
2521
2515
2522
Py_DECREF (args);
2523
+ Py_DECREF (kwargs);
2516
2524
Py_DECREF (res);
2517
2525
}
2518
2526
@@ -2632,7 +2640,7 @@ inline void rcparams(const std::map<std::string, std::string>& keywords = {}) {
2632
2640
PyDict_SetItemString (kwargs, it->first .c_str (), PyLong_FromLong (std::stoi (it->second .c_str ())));
2633
2641
else PyDict_SetItemString (kwargs, it->first .c_str (), PyString_FromString (it->second .c_str ()));
2634
2642
}
2635
-
2643
+
2636
2644
PyObject * update = PyObject_GetAttrString (detail::_interpreter::get ().s_python_function_rcparams , " update" );
2637
2645
PyObject * res = PyObject_Call (update, args, kwargs);
2638
2646
if (!res) throw std::runtime_error (" Call to rcParams.update() failed." );
@@ -2961,3 +2969,5 @@ class Plot
2961
2969
};
2962
2970
2963
2971
} // end namespace matplotlibcpp
2972
+
2973
+ #endif // !__MATPLOTLIBCPP__H__
0 commit comments