Procházet zdrojové kódy

Implemented wrapper corresponding to tick_params in matplotlib

belre9 před 5 roky
rodič
revize
8297ae81a0
1 změnil soubory, kde provedl 26 přidání a 0 odebrání
  1. 26 0
      matplotlibcpp.h

+ 26 - 0
matplotlibcpp.h

@@ -73,6 +73,7 @@ struct _interpreter {
     PyObject *s_python_function_ylabel;
     PyObject *s_python_function_xticks;
     PyObject *s_python_function_yticks;
+    PyObject *s_python_function_tick_params;
     PyObject *s_python_function_grid;
     PyObject *s_python_function_clf;
     PyObject *s_python_function_errorbar;
@@ -203,6 +204,7 @@ private:
         s_python_function_ylabel = safe_import(pymod, "ylabel");
         s_python_function_xticks = safe_import(pymod, "xticks");
         s_python_function_yticks = safe_import(pymod, "yticks");
+    	s_python_function_tick_params = safe_import(pymod, "tick_params");
         s_python_function_grid = safe_import(pymod, "grid");
         s_python_function_xlim = safe_import(pymod, "xlim");
         s_python_function_ion = safe_import(pymod, "ion");
@@ -1375,6 +1377,30 @@ inline void yticks(const std::vector<Numeric> &ticks, const std::map<std::string
     yticks(ticks, {}, keywords);
 }
 
+inline void tick_params(const std::map<std::string, std::string>& keywords, const std::string axis = "both")
+{
+  // construct positional args
+  PyObject* args;
+  args = PyTuple_New(1);
+  PyTuple_SetItem(args, 0, PyString_FromString(axis.c_str()));
+  
+  // construct keyword args
+  PyObject* kwargs = PyDict_New();
+  for (std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
+  {
+    PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
+  }
+  
+  
+  PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_tick_params, args, kwargs);
+  
+  Py_DECREF(args);
+  Py_DECREF(kwargs);
+  if (!res) throw std::runtime_error("Call to tick_params() failed");
+  
+  Py_DECREF(res);
+}
+
 inline void subplot(long nrows, long ncols, long plot_number)
 {
     // construct positional args