Browse Source

Adding possibility to choose dpi when saving

raphael.viards@magellium.fr 4 years ago
parent
commit
3af24b4182
1 changed files with 10 additions and 2 deletions
  1. 10 2
      matplotlibcpp.h

+ 10 - 2
matplotlibcpp.h

@@ -2439,7 +2439,7 @@ inline void pause(Numeric interval)
     Py_DECREF(res);
 }
 
-inline void save(const std::string& filename)
+inline void save(const std::string& filename, const int dpi=0)
 {
     detail::_interpreter::get();
 
@@ -2448,10 +2448,18 @@ inline void save(const std::string& filename)
     PyObject* args = PyTuple_New(1);
     PyTuple_SetItem(args, 0, pyfilename);
 
-    PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_save, args);
+    PyObject* kwargs = PyDict_New();
+
+    if(dpi > 0)
+    {
+        PyDict_SetItemString(kwargs, "dpi", PyLong_FromLong(dpi));
+    }
+
+    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(args);
+    Py_DECREF(kwargs);
     Py_DECREF(res);
 }