Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37b2113

Browse files
committed
default param for grid() + savefig + save is deprecated
1 parent ead6355 commit 37b2113

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

matplotlibcpp.h

+17-4
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ inline void ylabel(const std::string &str,
14921492
Py_DECREF(res);
14931493
}
14941494

1495-
inline void grid(bool flag) {
1495+
inline void grid(bool flag = true) {
14961496
PyObject *pyflag = flag ? Py_True : Py_False;
14971497
Py_INCREF(pyflag);
14981498

@@ -1579,21 +1579,34 @@ template <typename Numeric> inline void pause(Numeric interval) {
15791579
Py_DECREF(res);
15801580
}
15811581

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 = {}) {
15831584
PyObject *pyfilename = PyString_FromString(filename.c_str());
15841585

15851586
PyObject *args = PyTuple_New(1);
15861587
PyTuple_SetItem(args, 0, pyfilename);
15871588

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);
15901597
if (!res)
15911598
throw std::runtime_error("Call to save() failed.");
15921599

1600+
Py_DECREF(kwargs);
15931601
Py_DECREF(args);
15941602
Py_DECREF(res);
15951603
}
15961604

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+
15971610
inline void clf() {
15981611
PyObject *res =
15991612
PyObject_CallObject(detail::_interpreter::get().s_python_function_clf,

0 commit comments

Comments
 (0)