Selaa lähdekoodia

Added xlim() and ylim() to get the limits of a plot

Martino 8 vuotta sitten
vanhempi
commit
d430c696ef
1 muutettua tiedostoa jossa 32 lisäystä ja 0 poistoa
  1. 32 0
      matplotlibcpp.h

+ 32 - 0
matplotlibcpp.h

@@ -354,6 +354,38 @@ namespace matplotlibcpp {
 		Py_DECREF(args);
 		Py_DECREF(res);
 	}
+  
+  
+  double * xlim()
+  {
+    PyObject* args = PyTuple_New(0);
+		PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_xlim, args);
+    PyObject * left = PyTuple_GetItem(res,0);
+    PyObject * right = PyTuple_GetItem(res,1);
+    double * arr = new double[2];
+    arr[0] = PyFloat_AsDouble(left);
+    arr[1] = PyFloat_AsDouble(right);
+    
+		if(!res) throw std::runtime_error("Call to xlim() failed."); 
+    Py_DECREF(res);
+    return arr;
+  }
+  
+  
+  double * ylim()
+  {
+    PyObject* args = PyTuple_New(0);
+		PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_ylim, args);
+    PyObject * left = PyTuple_GetItem(res,0);
+    PyObject * right = PyTuple_GetItem(res,1);
+    double * arr = new double[2];
+    arr[0] = PyFloat_AsDouble(left);
+    arr[1] = PyFloat_AsDouble(right);
+    
+		if(!res) throw std::runtime_error("Call to ylim() failed."); 
+    Py_DECREF(res);
+    return arr;
+  }
 
     inline void subplot(long nrows, long ncols, long plot_number) {
         // construct positional args