diff --git a/matplotlibcpp.h b/matplotlibcpp.h index d95d46ad..1c4bba47 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -348,13 +348,6 @@ template <> struct select_npy_type { const static NPY_TYPES type = NPY template <> struct select_npy_type { const static NPY_TYPES type = NPY_ULONG; }; template <> struct select_npy_type { const static NPY_TYPES type = NPY_UINT64; }; -// Sanity checks; comment them out or change the numpy type below if you're compiling on -// a platform where they don't apply -static_assert(sizeof(long long) == 8); -template <> struct select_npy_type { const static NPY_TYPES type = NPY_INT64; }; -static_assert(sizeof(unsigned long long) == 8); -template <> struct select_npy_type { const static NPY_TYPES type = NPY_UINT64; }; - template PyObject* get_array(const std::vector& v) { @@ -2622,6 +2615,29 @@ inline void pause(Numeric interval) Py_DECREF(res); } +inline void savefig(const std::string &filename, + const std::map &keywords = {}) { + PyObject *pyfilename = PyString_FromString(filename.c_str()); + + PyObject *args = PyTuple_New(1); + PyTuple_SetItem(args, 0, pyfilename); + + PyObject *kwargs = PyDict_New(); + for (auto it = keywords.begin(); it != keywords.end(); ++it) { + PyDict_SetItemString(kwargs, it->first.c_str(), + PyUnicode_FromString(it->second.c_str())); + } + + PyObject *res = PyObject_Call( + detail::_interpreter::get().s_python_function_save, args, kwargs); + if (!res) + throw std::runtime_error("Call to save() failed."); + + Py_DECREF(kwargs); + Py_DECREF(args); + Py_DECREF(res); +} + inline void save(const std::string& filename, const int dpi=0) { detail::_interpreter::get();