diff --git a/examples/subplot.cpp b/examples/subplot.cpp new file mode 100644 index 0000000..bee322e --- /dev/null +++ b/examples/subplot.cpp @@ -0,0 +1,31 @@ +#define _USE_MATH_DEFINES +#include +#include "../matplotlibcpp.h" + +using namespace std; +namespace plt = matplotlibcpp; + +int main() +{ + // Prepare data + int n = 500; + std::vector x(n), y(n), z(n), w(n,2); + for(int i=0; i& y, const std::string& format = "") return stem(x, y, format); } +template +void text(Numeric x, Numeric y, const std::string& s = "") +{ + PyObject* args = PyTuple_New(3); + PyTuple_SetItem(args, 0, PyFloat_FromDouble(x)); + PyTuple_SetItem(args, 1, PyFloat_FromDouble(y)); + PyTuple_SetItem(args, 2, PyString_FromString(s.c_str())); + + PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_text, args); + if(!res) throw std::runtime_error("Call to text() failed."); + + Py_DECREF(args); + Py_DECREF(res); +} + + inline void figure() { PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_figure, detail::_interpreter::get().s_python_empty_tuple); @@ -978,6 +1002,19 @@ inline void title(const std::string &titlestr) Py_DECREF(res); } +inline void suptitle(const std::string &suptitlestr) +{ + PyObject* pysuptitlestr = PyString_FromString(suptitlestr.c_str()); + PyObject* args = PyTuple_New(1); + PyTuple_SetItem(args, 0, pysuptitlestr); + + PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_suptitle, args); + if(!res) throw std::runtime_error("Call to suptitle() failed."); + + Py_DECREF(args); + Py_DECREF(res); +} + inline void axis(const std::string &axisstr) { PyObject* str = PyString_FromString(axisstr.c_str());