@@ -1492,7 +1492,7 @@ inline void ylabel(const std::string &str,
1492
1492
Py_DECREF (res);
1493
1493
}
1494
1494
1495
- inline void grid (bool flag) {
1495
+ inline void grid (bool flag = true ) {
1496
1496
PyObject *pyflag = flag ? Py_True : Py_False;
1497
1497
Py_INCREF (pyflag);
1498
1498
@@ -1579,21 +1579,34 @@ template <typename Numeric> inline void pause(Numeric interval) {
1579
1579
Py_DECREF (res);
1580
1580
}
1581
1581
1582
- inline void save (const std::string &filename) {
1582
+ inline void savefig (const std::string &filename,
1583
+ const std::map<std::string, std::string> &keywords = {}) {
1583
1584
PyObject *pyfilename = PyString_FromString (filename.c_str ());
1584
1585
1585
1586
PyObject *args = PyTuple_New (1 );
1586
1587
PyTuple_SetItem (args, 0 , pyfilename);
1587
1588
1588
- PyObject *res = PyObject_CallObject (
1589
- detail::_interpreter::get ().s_python_function_save , args);
1589
+ PyObject *kwargs = PyDict_New ();
1590
+ for (auto it = keywords.begin (); it != keywords.end (); ++it) {
1591
+ PyDict_SetItemString (kwargs, it->first .c_str (),
1592
+ PyUnicode_FromString (it->second .c_str ()));
1593
+ }
1594
+
1595
+ PyObject *res = PyObject_Call (
1596
+ detail::_interpreter::get ().s_python_function_save , args, kwargs);
1590
1597
if (!res)
1591
1598
throw std::runtime_error (" Call to save() failed." );
1592
1599
1600
+ Py_DECREF (kwargs);
1593
1601
Py_DECREF (args);
1594
1602
Py_DECREF (res);
1595
1603
}
1596
1604
1605
+ inline void save (const std::string &filename) {
1606
+ std::cerr << " matplotlibcpp::save is deprecated, use savefig instead\n " ;
1607
+ matplotlibcpp::savefig (filename);
1608
+ }
1609
+
1597
1610
inline void clf () {
1598
1611
PyObject *res =
1599
1612
PyObject_CallObject (detail::_interpreter::get ().s_python_function_clf ,
0 commit comments