| 2012 | } |
| 2013 | |
| 2014 | inline void set_zlabel(const std::string &str, const std::map<std::string, std::string>& keywords = {}) |
| 2015 | { |
| 2016 | detail::_interpreter::get(); |
| 2017 | |
| 2018 | // Same as with plot_surface: We lazily load the modules here the first time |
| 2019 | // this function is called because I'm not sure that we can assume "matplotlib |
| 2020 | // installed" implies "mpl_toolkits installed" on all platforms, and we don't |
| 2021 | // want to require it for people who don't need 3d plots. |
| 2022 | static PyObject *mpl_toolkitsmod = nullptr, *axis3dmod = nullptr; |
| 2023 | if (!mpl_toolkitsmod) { |
| 2024 | PyObject* mpl_toolkits = PyString_FromString("mpl_toolkits"); |
| 2025 | PyObject* axis3d = PyString_FromString("mpl_toolkits.mplot3d"); |
| 2026 | if (!mpl_toolkits || !axis3d) { throw std::runtime_error("couldnt create string"); } |
| 2027 | |
| 2028 | mpl_toolkitsmod = PyImport_Import(mpl_toolkits); |
| 2029 | Py_DECREF(mpl_toolkits); |
| 2030 | if (!mpl_toolkitsmod) { throw std::runtime_error("Error loading module mpl_toolkits!"); } |
| 2031 | |
| 2032 | axis3dmod = PyImport_Import(axis3d); |
| 2033 | Py_DECREF(axis3d); |
| 2034 | if (!axis3dmod) { throw std::runtime_error("Error loading module mpl_toolkits.mplot3d!"); } |
| 2035 | } |
| 2036 | |
| 2037 | PyObject* pystr = PyString_FromString(str.c_str()); |
| 2038 | PyObject* args = PyTuple_New(1); |
| 2039 | PyTuple_SetItem(args, 0, pystr); |
| 2040 | |
| 2041 | PyObject* kwargs = PyDict_New(); |
| 2042 | for (auto it = keywords.begin(); it != keywords.end(); ++it) { |
| 2043 | PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str())); |
| 2044 | } |
| 2045 | |
| 2046 | PyObject *ax = |
| 2047 | PyObject_CallObject(detail::_interpreter::get().s_python_function_gca, |
| 2048 | detail::_interpreter::get().s_python_empty_tuple); |
| 2049 | if (!ax) throw std::runtime_error("Call to gca() failed."); |
| 2050 | Py_INCREF(ax); |
| 2051 | |
| 2052 | PyObject *zlabel = PyObject_GetAttrString(ax, "set_zlabel"); |
| 2053 | if (!zlabel) throw std::runtime_error("Attribute set_zlabel not found."); |
| 2054 | Py_INCREF(zlabel); |
| 2055 | |
| 2056 | PyObject *res = PyObject_Call(zlabel, args, kwargs); |
| 2057 | if (!res) throw std::runtime_error("Call to set_zlabel() failed."); |
| 2058 | Py_DECREF(zlabel); |
| 2059 | |
| 2060 | Py_DECREF(ax); |
| 2061 | Py_DECREF(args); |
| 2062 | Py_DECREF(kwargs); |
| 2063 | if (res) Py_DECREF(res); |
| 2064 | } |
| 2065 | |
| 2066 | inline void grid(bool flag) |
| 2067 | { |
nothing calls this directly
no outgoing calls
no test coverage detected