8000 Adding savefig function. · DamynChipman/matplotlib-cpp@8e280d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e280d2

Browse files
committed
Adding savefig function.
1 parent 73d633f commit 8e280d2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

matplotlibcpp.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,6 +2615,29 @@ inline void pause(Numeric interval)
26152615
Py_DECREF(res);
26162616
}
26172617

2618+
inline void savefig(const std::string &filename,
2619+
const std::map<std::string, std::string> &keywords = {}) {
2620+
PyObject *pyfilename = PyString_FromString(filename.c_str());
2621+
2622+
PyObject *args = PyTuple_New(1);
2623+
PyTuple_SetItem(args, 0, pyfilename);
2624+
2625+
PyObject *kwargs = PyDict_New();
2626+
for (auto it = keywords.begin(); it != keywords.end(); ++it) {
2627+
PyDict_SetItemString(kwargs, it->first.c_str(),
2628+
PyUnicode_FromString(it->second.c_str()));
2629+
}
2630+
2631+
PyObject *res = PyObject_Call(
2632+
detail::_interpreter::get().s_python_function_save, args, kwargs);
2633+
if (!res)
2634+
throw std::runtime_error("Call to save() failed.");
2635+
2636+
Py_DECREF(kwargs);
2637+
Py_DECREF(args);
2638+
Py_DECREF(res);
2639+
}
2640+
26182641
inline void save(const std::string& filename, const int dpi=0)
26192642
{
26202643
detail::_interpreter::get();

0 commit comments

Comments
 (0)
0