16 # define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 17 # include <numpy/arrayobject.h> 20 # include <opencv2/opencv.hpp> 21 # endif // WITH_OPENCV 27 # if CV_MAJOR_VERSION > 3 28 # define CV_BGR2RGB cv::COLOR_BGR2RGB 29 # define CV_BGRA2RGBA cv::COLOR_BGRA2RGBA 31 #endif // WITHOUT_NUMPY 33 #if PY_MAJOR_VERSION >= 3 34 # define PyString_FromString PyUnicode_FromString 35 # define PyInt_FromLong PyLong_FromLong 36 # define PyString_FromString PyUnicode_FromString 43 static std::string s_backend;
102 PyObject* fn = PyObject_GetAttrString(module, fname.c_str());
105 throw std::runtime_error(std::string(
"Couldn't find required function: ") + fname);
107 if (!PyFunction_Check(fn))
108 throw std::runtime_error(fname + std::string(
" is unexpectedly not a PyFunction."));
115 #ifndef WITHOUT_NUMPY 116 # if PY_MAJOR_VERSION >= 3 135 #if PY_MAJOR_VERSION >= 3 136 wchar_t name[] = L
"plotting";
138 char name[] =
"plotting";
140 Py_SetProgramName(name);
143 #ifndef WITHOUT_NUMPY 147 PyObject* matplotlibname = PyString_FromString(
"matplotlib");
148 PyObject* pyplotname = PyString_FromString(
"matplotlib.pyplot");
149 PyObject* cmname = PyString_FromString(
"matplotlib.cm");
150 PyObject* pylabname = PyString_FromString(
"pylab");
151 if (!pyplotname || !pylabname || !matplotlibname || !cmname) {
152 throw std::runtime_error(
"couldnt create string");
155 PyObject* matplotlib = PyImport_Import(matplotlibname);
156 Py_DECREF(matplotlibname);
159 throw std::runtime_error(
"Error loading module matplotlib!");
164 if (!s_backend.empty()) {
165 PyObject_CallMethod(matplotlib, const_cast<char*>(
"use"), const_cast<char*>(
"s"), s_backend.c_str());
168 PyObject* pymod = PyImport_Import(pyplotname);
169 Py_DECREF(pyplotname);
170 if (!pymod) {
throw std::runtime_error(
"Error loading module matplotlib.pyplot!"); }
172 s_python_colormap = PyImport_Import(cmname);
174 if (!s_python_colormap) {
throw std::runtime_error(
"Error loading module matplotlib.cm!"); }
176 PyObject* pylabmod = PyImport_Import(pylabname);
177 Py_DECREF(pylabname);
178 if (!pylabmod) {
throw std::runtime_error(
"Error loading module pylab!"); }
180 s_python_function_show =
safe_import(pymod,
"show");
181 s_python_function_close =
safe_import(pymod,
"close");
182 s_python_function_draw =
safe_import(pymod,
"draw");
183 s_python_function_pause =
safe_import(pymod,
"pause");
184 s_python_function_figure =
safe_import(pymod,
"figure");
185 s_python_function_fignum_exists =
safe_import(pymod,
"fignum_exists");
186 s_python_function_plot =
safe_import(pymod,
"plot");
187 s_python_function_quiver =
safe_import(pymod,
"quiver");
188 s_python_function_semilogx =
safe_import(pymod,
"semilogx");
189 s_python_function_semilogy =
safe_import(pymod,
"semilogy");
190 s_python_function_loglog =
safe_import(pymod,
"loglog");
191 s_python_function_fill =
safe_import(pymod,
"fill");
192 s_python_function_fill_between =
safe_import(pymod,
"fill_between");
193 s_python_function_hist =
safe_import(pymod,
"hist");
194 s_python_function_scatter =
safe_import(pymod,
"scatter");
195 s_python_function_subplot =
safe_import(pymod,
"subplot");
196 s_python_function_legend =
safe_import(pymod,
"legend");
197 s_python_function_ylim =
safe_import(pymod,
"ylim");
198 s_python_function_title =
safe_import(pymod,
"title");
199 s_python_function_axis =
safe_import(pymod,
"axis");
200 s_python_function_xlabel =
safe_import(pymod,
"xlabel");
201 s_python_function_ylabel =
safe_import(pymod,
"ylabel");
202 s_python_function_xticks =
safe_import(pymod,
"xticks");
203 s_python_function_yticks =
safe_import(pymod,
"yticks");
204 s_python_function_grid =
safe_import(pymod,
"grid");
205 s_python_function_xlim =
safe_import(pymod,
"xlim");
207 s_python_function_ginput =
safe_import(pymod,
"ginput");
208 s_python_function_save =
safe_import(pylabmod,
"savefig");
209 s_python_function_annotate =
safe_import(pymod,
"annotate");
211 s_python_function_errorbar =
safe_import(pymod,
"errorbar");
212 s_python_function_tight_layout =
safe_import(pymod,
"tight_layout");
213 s_python_function_stem =
safe_import(pymod,
"stem");
214 s_python_function_xkcd =
safe_import(pymod,
"xkcd");
215 s_python_function_text =
safe_import(pymod,
"text");
216 s_python_function_suptitle =
safe_import(pymod,
"suptitle");
218 s_python_function_subplots_adjust =
safe_import(pymod,
"subplots_adjust");
219 #ifndef WITHOUT_NUMPY 220 s_python_function_imshow =
safe_import(pymod,
"imshow");
223 s_python_empty_tuple = PyTuple_New(0);
236 detail::s_backend = name;
239 inline bool annotate(std::string annotation,
double x,
double y)
241 PyObject * xy = PyTuple_New(2);
242 PyObject * str = PyString_FromString(annotation.c_str());
244 PyTuple_SetItem(xy,0,PyFloat_FromDouble(x));
245 PyTuple_SetItem(xy,1,PyFloat_FromDouble(y));
247 PyObject* kwargs = PyDict_New();
248 PyDict_SetItemString(kwargs,
"xy", xy);
250 PyObject* args = PyTuple_New(1);
251 PyTuple_SetItem(args, 0, str);
258 if(res) Py_DECREF(res);
263 #ifndef WITHOUT_NUMPY 265 template <
typename T>
struct select_npy_type {
const static NPY_TYPES type = NPY_NOTYPE; };
266 template <>
struct select_npy_type<double> {
const static NPY_TYPES type = NPY_DOUBLE; };
267 template <>
struct select_npy_type<float> {
const static NPY_TYPES type = NPY_FLOAT; };
269 template <>
struct select_npy_type<int8_t> {
const static NPY_TYPES type = NPY_INT8; };
270 template <>
struct select_npy_type<int16_t> {
const static NPY_TYPES type = NPY_SHORT; };
271 template <>
struct select_npy_type<int32_t> {
const static NPY_TYPES type = NPY_INT; };
272 template <>
struct select_npy_type<int64_t> {
const static NPY_TYPES type = NPY_INT64; };
273 template <>
struct select_npy_type<uint8_t> {
const static NPY_TYPES type = NPY_UINT8; };
274 template <>
struct select_npy_type<uint16_t> {
const static NPY_TYPES type = NPY_USHORT; };
275 template <>
struct select_npy_type<uint32_t> {
const static NPY_TYPES type = NPY_ULONG; };
276 template <>
struct select_npy_type<uint64_t> {
const static NPY_TYPES type = NPY_UINT64; };
278 template<
typename Numeric>
283 if (type == NPY_NOTYPE)
285 std::vector<double> vd(v.size());
286 npy_intp vsize = v.size();
287 std::copy(v.begin(),v.end(),vd.begin());
288 PyObject* varray = PyArray_SimpleNewFromData(1, &vsize, NPY_DOUBLE, (
void*)(vd.data()));
292 npy_intp vsize = v.size();
293 PyObject* varray = PyArray_SimpleNewFromData(1, &vsize, type, (
void*)(v.data()));
297 template<
typename Numeric>
298 PyObject*
get_2darray(
const std::vector<::std::vector<Numeric>>& v)
301 if (v.size() < 1)
throw std::runtime_error(
"get_2d_array v too small");
303 npy_intp vsize[2] = {
static_cast<npy_intp
>(v.size()),
304 static_cast<npy_intp>(v[0].size())};
306 PyArrayObject *varray =
307 (PyArrayObject *)PyArray_SimpleNew(2, vsize, NPY_DOUBLE);
309 double *vd_begin =
static_cast<double *
>(PyArray_DATA(varray));
311 for (const ::std::vector<Numeric> &v_row : v) {
312 if (v_row.size() !=
static_cast<size_t>(vsize[1]))
313 throw std::runtime_error(
"Missmatched array size");
314 std::copy(v_row.begin(), v_row.end(), vd_begin);
315 vd_begin += vsize[1];
318 return reinterpret_cast<PyObject *
>(varray);
321 #else // fallback if we don't have numpy: copy every element of the given vector 323 template<
typename Numeric>
324 PyObject*
get_array(
const std::vector<Numeric>& v)
326 PyObject* list = PyList_New(v.size());
327 for(
size_t i = 0; i < v.size(); ++i) {
328 PyList_SetItem(list, i, PyFloat_FromDouble(v.at(i)));
333 #endif // WITHOUT_NUMPY 335 template<
typename Numeric>
336 bool plot(
const std::vector<Numeric> &x,
const std::vector<Numeric> &y,
const std::map<std::string, std::string>& keywords)
338 assert(x.size() == y.size());
345 PyObject* args = PyTuple_New(2);
346 PyTuple_SetItem(args, 0, xarray);
347 PyTuple_SetItem(args, 1, yarray);
350 PyObject* kwargs = PyDict_New();
351 for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
353 PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
360 if(res) Py_DECREF(res);
365 template <
typename Numeric>
367 const std::vector<::std::vector<Numeric>> &y,
368 const std::vector<::std::vector<Numeric>> &z,
369 const std::map<std::string, std::string> &keywords =
370 std::map<std::string, std::string>())
376 static PyObject *mpl_toolkitsmod =
nullptr, *axis3dmod =
nullptr;
377 if (!mpl_toolkitsmod) {
380 PyObject* mpl_toolkits = PyString_FromString(
"mpl_toolkits");
381 PyObject* axis3d = PyString_FromString(
"mpl_toolkits.mplot3d");
382 if (!mpl_toolkits || !axis3d) {
throw std::runtime_error(
"couldnt create string"); }
384 mpl_toolkitsmod = PyImport_Import(mpl_toolkits);
385 Py_DECREF(mpl_toolkits);
386 if (!mpl_toolkitsmod) {
throw std::runtime_error(
"Error loading module mpl_toolkits!"); }
388 axis3dmod = PyImport_Import(axis3d);
390 if (!axis3dmod) {
throw std::runtime_error(
"Error loading module mpl_toolkits.mplot3d!"); }
393 assert(x.size() == y.size());
394 assert(y.size() == z.size());
402 PyObject *args = PyTuple_New(3);
403 PyTuple_SetItem(args, 0, xarray);
404 PyTuple_SetItem(args, 1, yarray);
405 PyTuple_SetItem(args, 2, zarray);
408 PyObject *kwargs = PyDict_New();
409 PyDict_SetItemString(kwargs,
"rstride", PyInt_FromLong(1));
410 PyDict_SetItemString(kwargs,
"cstride", PyInt_FromLong(1));
412 PyObject *python_colormap_coolwarm = PyObject_GetAttrString(
415 PyDict_SetItemString(kwargs,
"cmap", python_colormap_coolwarm);
417 for (std::map<std::string, std::string>::const_iterator it = keywords.begin();
418 it != keywords.end(); ++it) {
419 PyDict_SetItemString(kwargs, it->first.c_str(),
420 PyString_FromString(it->second.c_str()));
427 if (!fig)
throw std::runtime_error(
"Call to figure() failed.");
429 PyObject *gca_kwargs = PyDict_New();
430 PyDict_SetItemString(gca_kwargs,
"projection", PyString_FromString(
"3d"));
432 PyObject *gca = PyObject_GetAttrString(fig,
"gca");
433 if (!gca)
throw std::runtime_error(
"No gca");
435 PyObject *
axis = PyObject_Call(
438 if (!axis)
throw std::runtime_error(
"No axis");
442 Py_DECREF(gca_kwargs);
444 PyObject *
plot_surface = PyObject_GetAttrString(axis,
"plot_surface");
445 if (!plot_surface)
throw std::runtime_error(
"No surface");
446 Py_INCREF(plot_surface);
447 PyObject *res = PyObject_Call(plot_surface, args, kwargs);
448 if (!res)
throw std::runtime_error(
"failed surface");
449 Py_DECREF(plot_surface);
454 if (res) Py_DECREF(res);
457 template<
typename Numeric>
458 bool stem(
const std::vector<Numeric> &x,
const std::vector<Numeric> &y,
const std::map<std::string, std::string>& keywords)
460 assert(x.size() == y.size());
467 PyObject* args = PyTuple_New(2);
468 PyTuple_SetItem(args, 0, xarray);
469 PyTuple_SetItem(args, 1, yarray);
472 PyObject* kwargs = PyDict_New();
473 for (std::map<std::string, std::string>::const_iterator it =
474 keywords.begin(); it != keywords.end(); ++it) {
475 PyDict_SetItemString(kwargs, it->first.c_str(),
476 PyString_FromString(it->second.c_str()));
479 PyObject* res = PyObject_Call(
490 template<
typename Numeric >
491 bool fill(
const std::vector<Numeric>& x,
const std::vector<Numeric>& y,
const std::map<std::string, std::string>& keywords)
493 assert(x.size() == y.size());
500 PyObject* args = PyTuple_New(2);
501 PyTuple_SetItem(args, 0, xarray);
502 PyTuple_SetItem(args, 1, yarray);
505 PyObject* kwargs = PyDict_New();
506 for (
auto it = keywords.begin(); it != keywords.end(); ++it) {
507 PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
515 if (res) Py_DECREF(res);
520 template<
typename Numeric >
521 bool fill_between(
const std::vector<Numeric>& x,
const std::vector<Numeric>& y1,
const std::vector<Numeric>& y2,
const std::map<std::string, std::string>& keywords)
523 assert(x.size() == y1.size());
524 assert(x.size() == y2.size());
532 PyObject* args = PyTuple_New(3);
533 PyTuple_SetItem(args, 0, xarray);
534 PyTuple_SetItem(args, 1, y1array);
535 PyTuple_SetItem(args, 2, y2array);
538 PyObject* kwargs = PyDict_New();
539 for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it) {
540 PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
547 if(res) Py_DECREF(res);
552 template<
typename Numeric>
553 bool hist(
const std::vector<Numeric>& y,
long bins=10,std::string color=
"b",
554 double alpha=1.0,
bool cumulative=
false)
559 PyObject* kwargs = PyDict_New();
560 PyDict_SetItemString(kwargs,
"bins", PyLong_FromLong(bins));
561 PyDict_SetItemString(kwargs,
"color", PyString_FromString(color.c_str()));
562 PyDict_SetItemString(kwargs,
"alpha", PyFloat_FromDouble(alpha));
563 PyDict_SetItemString(kwargs,
"cumulative", cumulative ? Py_True : Py_False);
565 PyObject* plot_args = PyTuple_New(1);
567 PyTuple_SetItem(plot_args, 0, yarray);
573 Py_DECREF(plot_args);
575 if(res) Py_DECREF(res);
580 #ifndef WITHOUT_NUMPY 582 void imshow(
void *ptr,
const NPY_TYPES type,
const int rows,
const int columns,
const int colors,
const std::map<std::string, std::string> &keywords)
584 assert(type == NPY_UINT8 || type == NPY_FLOAT);
585 assert(colors == 1 || colors == 3 || colors == 4);
590 npy_intp dims[3] = { rows, columns, colors };
591 PyObject *args = PyTuple_New(1);
592 PyTuple_SetItem(args, 0, PyArray_SimpleNewFromData(colors == 1 ? 2 : 3, dims, type, ptr));
595 PyObject* kwargs = PyDict_New();
596 for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
598 PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
605 throw std::runtime_error(
"Call to imshow() failed");
610 void imshow(
const unsigned char *ptr,
const int rows,
const int columns,
const int colors,
const std::map<std::string, std::string> &keywords = {})
615 void imshow(
const float *ptr,
const int rows,
const int columns,
const int colors,
const std::map<std::string, std::string> &keywords = {})
621 void imshow(
const cv::Mat &image,
const std::map<std::string, std::string> &keywords = {})
625 NPY_TYPES npy_type = NPY_UINT8;
626 switch (image.type() & CV_MAT_DEPTH_MASK) {
632 npy_type = NPY_FLOAT;
635 image.convertTo(image2, CV_MAKETYPE(CV_8U, image.channels()));
639 switch (image2.channels()) {
641 cv::cvtColor(image2, image2, CV_BGR2RGB);
644 cv::cvtColor(image2, image2, CV_BGRA2RGBA);
647 internal::imshow(image2.data, npy_type, image2.rows, image2.cols, image2.channels(), keywords);
649 #endif // WITH_OPENCV 650 #endif // WITHOUT_NUMPY 652 template<
typename NumericX,
typename NumericY>
654 const std::vector<NumericY>& y,
657 assert(x.size() == y.size());
662 PyObject* kwargs = PyDict_New();
663 PyDict_SetItemString(kwargs,
"s", PyLong_FromLong(s));
665 PyObject* plot_args = PyTuple_New(2);
666 PyTuple_SetItem(plot_args, 0, xarray);
667 PyTuple_SetItem(plot_args, 1, yarray);
671 Py_DECREF(plot_args);
673 if(res) Py_DECREF(res);
678 template <
typename Numeric>
679 bool bar(
const std::vector<Numeric> & x,
680 const std::vector<Numeric> & y,
681 std::string ec =
"black",
682 std::string ls =
"-",
684 const std::map<std::string, std::string> & keywords = {}) {
688 PyObject * kwargs = PyDict_New();
690 PyDict_SetItemString(kwargs,
"ec", PyString_FromString(ec.c_str()));
691 PyDict_SetItemString(kwargs,
"ls", PyString_FromString(ls.c_str()));
692 PyDict_SetItemString(kwargs,
"lw", PyFloat_FromDouble(lw));
694 for (std::map<std::string, std::string>::const_iterator it =
696 it != keywords.end();
698 PyDict_SetItemString(
699 kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
702 PyObject * plot_args = PyTuple_New(2);
703 PyTuple_SetItem(plot_args, 0, xarray);
704 PyTuple_SetItem(plot_args, 1, yarray);
706 PyObject * res = PyObject_Call(
709 Py_DECREF(plot_args);
711 if (res) Py_DECREF(res);
716 template <
typename Numeric>
717 bool bar(
const std::vector<Numeric> & y,
718 std::string ec =
"black",
719 std::string ls =
"-",
721 const std::map<std::string, std::string> & keywords = {}) {
722 using T =
typename std::remove_reference<decltype(y)>::type::value_type;
725 for (std::size_t i = 0; i < y.size(); i++) { x.push_back(i); }
727 return bar(x, y, ec, ls, lw, keywords);
733 PyObject* kwargs = PyDict_New();
734 for (std::map<std::string, double>::const_iterator it =
735 keywords.begin(); it != keywords.end(); ++it) {
736 PyDict_SetItemString(kwargs, it->first.c_str(),
737 PyFloat_FromDouble(it->second));
741 PyObject* plot_args = PyTuple_New(0);
745 Py_DECREF(plot_args);
747 if(res) Py_DECREF(res);
752 template<
typename Numeric>
753 bool named_hist(std::string label,
const std::vector<Numeric>& y,
long bins=10, std::string color=
"b",
double alpha=1.0)
757 PyObject* kwargs = PyDict_New();
758 PyDict_SetItemString(kwargs,
"label", PyString_FromString(label.c_str()));
759 PyDict_SetItemString(kwargs,
"bins", PyLong_FromLong(bins));
760 PyDict_SetItemString(kwargs,
"color", PyString_FromString(color.c_str()));
761 PyDict_SetItemString(kwargs,
"alpha", PyFloat_FromDouble(alpha));
764 PyObject* plot_args = PyTuple_New(1);
765 PyTuple_SetItem(plot_args, 0, yarray);
769 Py_DECREF(plot_args);
771 if(res) Py_DECREF(res);
776 template<
typename NumericX,
typename NumericY>
777 bool plot(
const std::vector<NumericX>& x,
const std::vector<NumericY>& y,
const std::string& s =
"")
779 assert(x.size() == y.size());
784 PyObject* pystring = PyString_FromString(s.c_str());
786 PyObject* plot_args = PyTuple_New(3);
787 PyTuple_SetItem(plot_args, 0, xarray);
788 PyTuple_SetItem(plot_args, 1, yarray);
789 PyTuple_SetItem(plot_args, 2, pystring);
793 Py_DECREF(plot_args);
794 if(res) Py_DECREF(res);
799 template<
typename NumericX,
typename NumericY,
typename NumericU,
typename NumericW>
800 bool quiver(
const std::vector<NumericX>& x,
const std::vector<NumericY>& y,
const std::vector<NumericU>& u,
const std::vector<NumericW>& w,
const std::map<std::string, std::string>& keywords = {})
802 assert(x.size() == y.size() && x.size() == u.size() && u.size() == w.size());
809 PyObject* plot_args = PyTuple_New(4);
810 PyTuple_SetItem(plot_args, 0, xarray);
811 PyTuple_SetItem(plot_args, 1, yarray);
812 PyTuple_SetItem(plot_args, 2, uarray);
813 PyTuple_SetItem(plot_args, 3, warray);
816 PyObject* kwargs = PyDict_New();
817 for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
819 PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
822 PyObject* res = PyObject_Call(
826 Py_DECREF(plot_args);
833 template<
typename NumericX,
typename NumericY>
834 bool stem(
const std::vector<NumericX>& x,
const std::vector<NumericY>& y,
const std::string& s =
"")
836 assert(x.size() == y.size());
841 PyObject* pystring = PyString_FromString(s.c_str());
843 PyObject* plot_args = PyTuple_New(3);
844 PyTuple_SetItem(plot_args, 0, xarray);
845 PyTuple_SetItem(plot_args, 1, yarray);
846 PyTuple_SetItem(plot_args, 2, pystring);
848 PyObject* res = PyObject_CallObject(
851 Py_DECREF(plot_args);
858 template<
typename NumericX,
typename NumericY>
859 bool semilogx(
const std::vector<NumericX>& x,
const std::vector<NumericY>& y,
const std::string& s =
"")
861 assert(x.size() == y.size());
866 PyObject* pystring = PyString_FromString(s.c_str());
868 PyObject* plot_args = PyTuple_New(3);
869 PyTuple_SetItem(plot_args, 0, xarray);
870 PyTuple_SetItem(plot_args, 1, yarray);
871 PyTuple_SetItem(plot_args, 2, pystring);
875 Py_DECREF(plot_args);
876 if(res) Py_DECREF(res);
881 template<
typename NumericX,
typename NumericY>
882 bool semilogy(
const std::vector<NumericX>& x,
const std::vector<NumericY>& y,
const std::string& s =
"")
884 assert(x.size() == y.size());
889 PyObject* pystring = PyString_FromString(s.c_str());
891 PyObject* plot_args = PyTuple_New(3);
892 PyTuple_SetItem(plot_args, 0, xarray);
893 PyTuple_SetItem(plot_args, 1, yarray);
894 PyTuple_SetItem(plot_args, 2, pystring);
898 Py_DECREF(plot_args);
899 if(res) Py_DECREF(res);
904 template<
typename NumericX,
typename NumericY>
905 bool loglog(
const std::vector<NumericX>& x,
const std::vector<NumericY>& y,
const std::string& s =
"")
907 assert(x.size() == y.size());
912 PyObject* pystring = PyString_FromString(s.c_str());
914 PyObject* plot_args = PyTuple_New(3);
915 PyTuple_SetItem(plot_args, 0, xarray);
916 PyTuple_SetItem(plot_args, 1, yarray);
917 PyTuple_SetItem(plot_args, 2, pystring);
921 Py_DECREF(plot_args);
922 if(res) Py_DECREF(res);
927 template<
typename NumericX,
typename NumericY>
928 bool errorbar(
const std::vector<NumericX> &x,
const std::vector<NumericY> &y,
const std::vector<NumericX> &yerr,
const std::map<std::string, std::string> &keywords = {})
930 assert(x.size() == y.size());
937 PyObject* kwargs = PyDict_New();
938 for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
940 PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
943 PyDict_SetItemString(kwargs,
"yerr", yerrarray);
945 PyObject *plot_args = PyTuple_New(2);
946 PyTuple_SetItem(plot_args, 0, xarray);
947 PyTuple_SetItem(plot_args, 1, yarray);
952 Py_DECREF(plot_args);
957 throw std::runtime_error(
"Call to errorbar() failed.");
962 template<
typename Numeric>
963 bool named_plot(
const std::string& name,
const std::vector<Numeric>& y,
const std::string& format =
"")
965 PyObject* kwargs = PyDict_New();
966 PyDict_SetItemString(kwargs,
"label", PyString_FromString(name.c_str()));
970 PyObject* pystring = PyString_FromString(format.c_str());
972 PyObject* plot_args = PyTuple_New(2);
974 PyTuple_SetItem(plot_args, 0, yarray);
975 PyTuple_SetItem(plot_args, 1, pystring);
980 Py_DECREF(plot_args);
981 if (res) Py_DECREF(res);
986 template<
typename Numeric>
987 bool named_plot(
const std::string& name,
const std::vector<Numeric>& x,
const std::vector<Numeric>& y,
const std::string& format =
"")
989 PyObject* kwargs = PyDict_New();
990 PyDict_SetItemString(kwargs,
"label", PyString_FromString(name.c_str()));
995 PyObject* pystring = PyString_FromString(format.c_str());
997 PyObject* plot_args = PyTuple_New(3);
998 PyTuple_SetItem(plot_args, 0, xarray);
999 PyTuple_SetItem(plot_args, 1, yarray);
1000 PyTuple_SetItem(plot_args, 2, pystring);
1005 Py_DECREF(plot_args);
1006 if (res) Py_DECREF(res);
1011 template<
typename Numeric>
1012 bool named_semilogx(
const std::string& name,
const std::vector<Numeric>& x,
const std::vector<Numeric>& y,
const std::string& format =
"")
1014 PyObject* kwargs = PyDict_New();
1015 PyDict_SetItemString(kwargs,
"label", PyString_FromString(name.c_str()));
1020 PyObject* pystring = PyString_FromString(format.c_str());
1022 PyObject* plot_args = PyTuple_New(3);
1023 PyTuple_SetItem(plot_args, 0, xarray);
1024 PyTuple_SetItem(plot_args, 1, yarray);
1025 PyTuple_SetItem(plot_args, 2, pystring);
1030 Py_DECREF(plot_args);
1031 if (res) Py_DECREF(res);
1036 template<
typename Numeric>
1037 bool named_semilogy(
const std::string& name,
const std::vector<Numeric>& x,
const std::vector<Numeric>& y,
const std::string& format =
"")
1039 PyObject* kwargs = PyDict_New();
1040 PyDict_SetItemString(kwargs,
"label", PyString_FromString(name.c_str()));
1045 PyObject* pystring = PyString_FromString(format.c_str());
1047 PyObject* plot_args = PyTuple_New(3);
1048 PyTuple_SetItem(plot_args, 0, xarray);
1049 PyTuple_SetItem(plot_args, 1, yarray);
1050 PyTuple_SetItem(plot_args, 2, pystring);
1055 Py_DECREF(plot_args);
1056 if (res) Py_DECREF(res);
1061 template<
typename Numeric>
1062 bool named_loglog(
const std::string& name,
const std::vector<Numeric>& x,
const std::vector<Numeric>& y,
const std::string& format =
"")
1064 PyObject* kwargs = PyDict_New();
1065 PyDict_SetItemString(kwargs,
"label", PyString_FromString(name.c_str()));
1070 PyObject* pystring = PyString_FromString(format.c_str());
1072 PyObject* plot_args = PyTuple_New(3);
1073 PyTuple_SetItem(plot_args, 0, xarray);
1074 PyTuple_SetItem(plot_args, 1, yarray);
1075 PyTuple_SetItem(plot_args, 2, pystring);
1080 Py_DECREF(plot_args);
1081 if (res) Py_DECREF(res);
1086 template<
typename Numeric>
1087 bool plot(
const std::vector<Numeric>& y,
const std::string& format =
"")
1089 std::vector<Numeric> x(y.size());
1090 for(
size_t i=0; i<x.size(); ++i) x.at(i) = i;
1091 return plot(x,y,format);
1094 template<
typename Numeric>
1095 bool plot(
const std::vector<Numeric>& y,
const std::map<std::string, std::string>& keywords)
1097 std::vector<Numeric> x(y.size());
1098 for(
size_t i=0; i<x.size(); ++i) x.at(i) = i;
1099 return plot(x,y,keywords);
1102 template<
typename Numeric>
1103 bool stem(
const std::vector<Numeric>& y,
const std::string& format =
"")
1105 std::vector<Numeric> x(y.size());
1106 for (
size_t i = 0; i < x.size(); ++i) x.at(i) = i;
1107 return stem(x, y, format);
1110 template<
typename Numeric>
1111 void text(Numeric x, Numeric y,
const std::string& s =
"")
1113 PyObject* args = PyTuple_New(3);
1114 PyTuple_SetItem(args, 0, PyFloat_FromDouble(x));
1115 PyTuple_SetItem(args, 1, PyFloat_FromDouble(y));
1116 PyTuple_SetItem(args, 2, PyString_FromString(s.c_str()));
1119 if(!res)
throw std::runtime_error(
"Call to text() failed.");
1137 PyObject *args = PyTuple_New(1);
1138 PyTuple_SetItem(args, 0, PyLong_FromLong(number));
1143 if(!res)
throw std::runtime_error(
"Call to figure() failed.");
1145 PyObject* num = PyObject_GetAttrString(res,
"number");
1146 if (!num)
throw std::runtime_error(
"Could not get number attribute of figure object");
1147 const long figureNumber = PyLong_AsLong(num);
1152 return figureNumber;
1160 PyObject *args = PyTuple_New(1);
1161 PyTuple_SetItem(args, 0, PyLong_FromLong(number));
1163 if(!res)
throw std::runtime_error(
"Call to fignum_exists() failed.");
1165 bool ret = PyObject_IsTrue(res);
1177 const size_t dpi = 100;
1178 PyObject* size = PyTuple_New(2);
1179 PyTuple_SetItem(size, 0, PyFloat_FromDouble((
double)w / dpi));
1180 PyTuple_SetItem(size, 1, PyFloat_FromDouble((
double)h / dpi));
1182 PyObject* kwargs = PyDict_New();
1183 PyDict_SetItemString(kwargs,
"figsize", size);
1184 PyDict_SetItemString(kwargs,
"dpi", PyLong_FromSize_t(dpi));
1191 if(!res)
throw std::runtime_error(
"Call to figure_size() failed.");
1198 if(!res)
throw std::runtime_error(
"Call to legend() failed.");
1203 template<
typename Numeric>
1204 void ylim(Numeric left, Numeric right)
1206 PyObject* list = PyList_New(2);
1207 PyList_SetItem(list, 0, PyFloat_FromDouble(left));
1208 PyList_SetItem(list, 1, PyFloat_FromDouble(right));
1210 PyObject* args = PyTuple_New(1);
1211 PyTuple_SetItem(args, 0, list);
1214 if(!res)
throw std::runtime_error(
"Call to ylim() failed.");
1220 template<
typename Numeric>
1221 void xlim(Numeric left, Numeric right)
1223 PyObject* list = PyList_New(2);
1224 PyList_SetItem(list, 0, PyFloat_FromDouble(left));
1225 PyList_SetItem(list, 1, PyFloat_FromDouble(right));
1227 PyObject* args = PyTuple_New(1);
1228 PyTuple_SetItem(args, 0, list);
1231 if(!res)
throw std::runtime_error(
"Call to xlim() failed.");
1240 PyObject* args = PyTuple_New(0);
1242 PyObject* left = PyTuple_GetItem(res,0);
1243 PyObject* right = PyTuple_GetItem(res,1);
1245 double* arr =
new double[2];
1246 arr[0] = PyFloat_AsDouble(left);
1247 arr[1] = PyFloat_AsDouble(right);
1249 if(!res)
throw std::runtime_error(
"Call to xlim() failed.");
1258 PyObject* args = PyTuple_New(0);
1260 PyObject* left = PyTuple_GetItem(res,0);
1261 PyObject* right = PyTuple_GetItem(res,1);
1263 double* arr =
new double[2];
1264 arr[0] = PyFloat_AsDouble(left);
1265 arr[1] = PyFloat_AsDouble(right);
1267 if(!res)
throw std::runtime_error(
"Call to ylim() failed.");
1273 template<
typename Numeric>
1274 inline void xticks(
const std::vector<Numeric> &ticks,
const std::vector<std::string> &labels = {},
const std::map<std::string, std::string>& keywords = {})
1276 assert(labels.size() == 0 || ticks.size() == labels.size());
1279 PyObject* ticksarray =
get_array(ticks);
1282 if(labels.size() == 0) {
1284 args = PyTuple_New(1);
1285 PyTuple_SetItem(args, 0, ticksarray);
1288 PyObject* labelstuple = PyTuple_New(labels.size());
1289 for (
size_t i = 0; i < labels.size(); i++)
1290 PyTuple_SetItem(labelstuple, i, PyUnicode_FromString(labels[i].c_str()));
1293 args = PyTuple_New(2);
1294 PyTuple_SetItem(args, 0, ticksarray);
1295 PyTuple_SetItem(args, 1, labelstuple);
1299 PyObject* kwargs = PyDict_New();
1300 for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
1302 PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
1309 if(!res)
throw std::runtime_error(
"Call to xticks() failed");
1314 template<
typename Numeric>
1315 inline void xticks(
const std::vector<Numeric> &ticks,
const std::map<std::string, std::string>& keywords)
1317 xticks(ticks, {}, keywords);
1320 template<
typename Numeric>
1321 inline void yticks(
const std::vector<Numeric> &ticks,
const std::vector<std::string> &labels = {},
const std::map<std::string, std::string>& keywords = {})
1323 assert(labels.size() == 0 || ticks.size() == labels.size());
1326 PyObject* ticksarray =
get_array(ticks);
1329 if(labels.size() == 0) {
1331 args = PyTuple_New(1);
1332 PyTuple_SetItem(args, 0, ticksarray);
1335 PyObject* labelstuple = PyTuple_New(labels.size());
1336 for (
size_t i = 0; i < labels.size(); i++)
1337 PyTuple_SetItem(labelstuple, i, PyUnicode_FromString(labels[i].c_str()));
1340 args = PyTuple_New(2);
1341 PyTuple_SetItem(args, 0, ticksarray);
1342 PyTuple_SetItem(args, 1, labelstuple);
1346 PyObject* kwargs = PyDict_New();
1347 for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
1349 PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
1356 if(!res)
throw std::runtime_error(
"Call to yticks() failed");
1361 template<
typename Numeric>
1362 inline void yticks(
const std::vector<Numeric> &ticks,
const std::map<std::string, std::string>& keywords)
1364 yticks(ticks, {}, keywords);
1367 inline void subplot(
long nrows,
long ncols,
long plot_number)
1370 PyObject* args = PyTuple_New(3);
1371 PyTuple_SetItem(args, 0, PyFloat_FromDouble(nrows));
1372 PyTuple_SetItem(args, 1, PyFloat_FromDouble(ncols));
1373 PyTuple_SetItem(args, 2, PyFloat_FromDouble(plot_number));
1376 if(!res)
throw std::runtime_error(
"Call to subplot() failed.");
1382 inline void title(
const std::string &titlestr,
const std::map<std::string, std::string> &keywords = {})
1384 PyObject* pytitlestr = PyString_FromString(titlestr.c_str());
1385 PyObject* args = PyTuple_New(1);
1386 PyTuple_SetItem(args, 0, pytitlestr);
1388 PyObject* kwargs = PyDict_New();
1389 for (
auto it = keywords.begin(); it != keywords.end(); ++it) {
1390 PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
1394 if(!res)
throw std::runtime_error(
"Call to title() failed.");
1401 inline void suptitle(
const std::string &suptitlestr,
const std::map<std::string, std::string> &keywords = {})
1403 PyObject* pysuptitlestr = PyString_FromString(suptitlestr.c_str());
1404 PyObject* args = PyTuple_New(1);
1405 PyTuple_SetItem(args, 0, pysuptitlestr);
1407 PyObject* kwargs = PyDict_New();
1408 for (
auto it = keywords.begin(); it != keywords.end(); ++it) {
1409 PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
1413 if(!res)
throw std::runtime_error(
"Call to suptitle() failed.");
1420 inline void axis(
const std::string &axisstr)
1422 PyObject* str = PyString_FromString(axisstr.c_str());
1423 PyObject* args = PyTuple_New(1);
1424 PyTuple_SetItem(args, 0, str);
1427 if(!res)
throw std::runtime_error(
"Call to title() failed.");
1433 inline void xlabel(
const std::string &str,
const std::map<std::string, std::string> &keywords = {})
1435 PyObject* pystr = PyString_FromString(str.c_str());
1436 PyObject* args = PyTuple_New(1);
1437 PyTuple_SetItem(args, 0, pystr);
1439 PyObject* kwargs = PyDict_New();
1440 for (
auto it = keywords.begin(); it != keywords.end(); ++it) {
1441 PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
1445 if(!res)
throw std::runtime_error(
"Call to xlabel() failed.");
1452 inline void ylabel(
const std::string &str,
const std::map<std::string, std::string>& keywords = {})
1454 PyObject* pystr = PyString_FromString(str.c_str());
1455 PyObject* args = PyTuple_New(1);
1456 PyTuple_SetItem(args, 0, pystr);
1458 PyObject* kwargs = PyDict_New();
1459 for (
auto it = keywords.begin(); it != keywords.end(); ++it) {
1460 PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
1464 if(!res)
throw std::runtime_error(
"Call to ylabel() failed.");
1473 PyObject* pyflag = flag ? Py_True : Py_False;
1476 PyObject* args = PyTuple_New(1);
1477 PyTuple_SetItem(args, 0, pyflag);
1480 if(!res)
throw std::runtime_error(
"Call to grid() failed.");
1486 inline void show(
const bool block =
true)
1491 res = PyObject_CallObject(
1497 PyObject *kwargs = PyDict_New();
1498 PyDict_SetItemString(kwargs,
"block", Py_False);
1504 if (!res)
throw std::runtime_error(
"Call to show() failed.");
1511 PyObject* res = PyObject_CallObject(
1515 if (!res)
throw std::runtime_error(
"Call to close() failed.");
1522 PyObject *kwargs = PyDict_New();
1530 throw std::runtime_error(
"Call to show() failed.");
1537 PyObject* res = PyObject_CallObject(
1541 if (!res)
throw std::runtime_error(
"Call to draw() failed.");
1546 template<
typename Numeric>
1549 PyObject* args = PyTuple_New(1);
1550 PyTuple_SetItem(args, 0, PyFloat_FromDouble(interval));
1553 if(!res)
throw std::runtime_error(
"Call to pause() failed.");
1559 inline void save(
const std::string& filename)
1561 PyObject* pyfilename = PyString_FromString(filename.c_str());
1563 PyObject* args = PyTuple_New(1);
1564 PyTuple_SetItem(args, 0, pyfilename);
1567 if (!res)
throw std::runtime_error(
"Call to save() failed.");
1574 PyObject *res = PyObject_CallObject(
1578 if (!res)
throw std::runtime_error(
"Call to clf() failed.");
1584 PyObject *res = PyObject_CallObject(
1588 if (!res)
throw std::runtime_error(
"Call to ion() failed.");
1593 inline std::vector<std::array<double, 2>>
ginput(
const int numClicks = 1,
const std::map<std::string, std::string>& keywords = {})
1595 PyObject *args = PyTuple_New(1);
1596 PyTuple_SetItem(args, 0, PyLong_FromLong(numClicks));
1599 PyObject* kwargs = PyDict_New();
1600 for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
1602 PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
1605 PyObject* res = PyObject_Call(
1610 if (!res)
throw std::runtime_error(
"Call to ginput() failed.");
1612 const size_t len = PyList_Size(res);
1613 std::vector<std::array<double, 2>> out;
1615 for (
size_t i = 0; i < len; i++) {
1616 PyObject *current = PyList_GetItem(res, i);
1617 std::array<double, 2> position;
1618 position[0] = PyFloat_AsDouble(PyTuple_GetItem(current, 0));
1619 position[1] = PyFloat_AsDouble(PyTuple_GetItem(current, 1));
1620 out.push_back(position);
1629 PyObject *res = PyObject_CallObject(
1633 if (!res)
throw std::runtime_error(
"Call to tight_layout() failed.");
1642 template<
typename T>
1643 using is_function =
typename std::is_function<std::remove_pointer<std::remove_reference<T>>>::type;
1645 template<
bool obj,
typename T>
1648 template<
typename T>
1654 template<
typename T>
1657 struct Fallback {
void operator()(); };
1658 struct Derived : T, Fallback { };
1660 template<
typename U, U>
struct Check;
1662 template<
typename U>
1663 static std::true_type test( ... );
1665 template<
typename U>
1666 static std::false_type test( Check<
void(Fallback::*)(), &U::operator()>* );
1669 typedef decltype(test<Derived>(
nullptr)) type;
1670 typedef decltype(&Fallback::operator()) dtype;
1671 static constexpr
bool value = type::value;
1674 template<typename T>
1681 template<
typename IsYDataCallable>
1687 template<
typename IterableX,
typename IterableY>
1688 bool operator()(
const IterableX& x,
const IterableY& y,
const std::string& format)
1691 using std::distance;
1695 auto xs = distance(begin(x), end(x));
1696 auto ys = distance(begin(y), end(y));
1697 assert(xs == ys &&
"x and y data must have the same number of elements!");
1699 PyObject* xlist = PyList_New(xs);
1700 PyObject* ylist = PyList_New(ys);
1701 PyObject* pystring = PyString_FromString(format.c_str());
1703 auto itx = begin(x), ity = begin(y);
1704 for(
size_t i = 0; i < xs; ++i) {
1705 PyList_SetItem(xlist, i, PyFloat_FromDouble(*itx++));
1706 PyList_SetItem(ylist, i, PyFloat_FromDouble(*ity++));
1709 PyObject* plot_args = PyTuple_New(3);
1710 PyTuple_SetItem(plot_args, 0, xlist);
1711 PyTuple_SetItem(plot_args, 1, ylist);
1712 PyTuple_SetItem(plot_args, 2, pystring);
1716 Py_DECREF(plot_args);
1717 if(res) Py_DECREF(res);
1726 template<
typename Iterable,
typename Callable>
1727 bool operator()(
const Iterable& ticks,
const Callable& f,
const std::string& format)
1729 if(begin(ticks) == end(ticks))
return true;
1733 std::vector<double> y;
1734 for(
auto x : ticks) y.push_back(f(x));
1742 template<
typename... Args>
1745 template<
typename A,
typename B,
typename... Args>
1746 bool plot(
const A& a,
const B& b,
const std::string& format, Args... args)
1755 inline bool plot(
const std::vector<double>& x,
const std::vector<double>& y,
const std::string& format =
"") {
1756 return plot<double,double>(x,y,format);
1759 inline bool plot(
const std::vector<double>& y,
const std::string& format =
"") {
1760 return plot<double>(y,format);
1763 inline bool plot(
const std::vector<double>& x,
const std::vector<double>& y,
const std::map<std::string, std::string>& keywords) {
1764 return plot<double>(x,y,keywords);
1775 template<
typename Numeric>
1776 Plot(
const std::string& name,
const std::vector<Numeric>& x,
const std::vector<Numeric>& y,
const std::string& format =
"") {
1778 assert(x.size() == y.size());
1780 PyObject* kwargs = PyDict_New();
1782 PyDict_SetItemString(kwargs,
"label", PyString_FromString(name.c_str()));
1787 PyObject* pystring = PyString_FromString(format.c_str());
1789 PyObject* plot_args = PyTuple_New(3);
1790 PyTuple_SetItem(plot_args, 0, xarray);
1791 PyTuple_SetItem(plot_args, 1, yarray);
1792 PyTuple_SetItem(plot_args, 2, pystring);
1797 Py_DECREF(plot_args);
1801 line= PyList_GetItem(res, 0);
1804 set_data_fct = PyObject_GetAttrString(line,
"set_data");
1813 Plot(
const std::string& name =
"",
const std::string& format =
"")
1814 :
Plot(name, std::vector<double>(), std::vector<double>(), format) {}
1816 template<
typename Numeric>
1817 bool update(
const std::vector<Numeric>& x,
const std::vector<Numeric>& y) {
1818 assert(x.size() == y.size());
1824 PyObject* plot_args = PyTuple_New(2);
1825 PyTuple_SetItem(plot_args, 0, xarray);
1826 PyTuple_SetItem(plot_args, 1, yarray);
1828 PyObject* res = PyObject_CallObject(set_data_fct, plot_args);
1829 if (res) Py_DECREF(res);
1837 return update(std::vector<double>(), std::vector<double>());
1844 auto remove_fct = PyObject_GetAttrString(line,
"remove");
1845 PyObject* args = PyTuple_New(0);
1846 PyObject* res = PyObject_CallObject(remove_fct, args);
1847 if (res) Py_DECREF(res);
1861 Py_DECREF(set_data_fct);
1865 PyObject* line =
nullptr;
1866 PyObject* set_data_fct =
nullptr;
bool named_plot(const std::string &name, const std::vector< Numeric > &y, const std::string &format="")
Definition: matplotlibcpp.h:963
PyObject * s_python_function_text
Definition: matplotlibcpp.h:84
PyObject * s_python_function_clf
Definition: matplotlibcpp.h:76
PyObject * s_python_colormap
Definition: matplotlibcpp.h:80
void ylim(Numeric left, Numeric right)
Definition: matplotlibcpp.h:1204
void xticks(const std::vector< Numeric > &ticks, const std::vector< std::string > &labels={}, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:1274
Plot(const std::string &name="", const std::string &format="")
Definition: matplotlibcpp.h:1813
void plot_surface(const std::vector<::std::vector< Numeric >> &x, const std::vector<::std::vector< Numeric >> &y, const std::vector<::std::vector< Numeric >> &z, const std::map< std::string, std::string > &keywords=std::map< std::string, std::string >())
Definition: matplotlibcpp.h:366
PyObject * s_python_function_show
Definition: matplotlibcpp.h:46
PyObject * s_python_function_ylim
Definition: matplotlibcpp.h:68
bool fignum_exists(long number)
Definition: matplotlibcpp.h:1155
void grid(bool flag)
Definition: matplotlibcpp.h:1471
void xkcd()
Definition: matplotlibcpp.h:1520
PyObject * s_python_function_xlabel
Definition: matplotlibcpp.h:71
void yticks(const std::vector< Numeric > &ticks, const std::vector< std::string > &labels={}, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:1321
PyObject * s_python_function_grid
Definition: matplotlibcpp.h:75
PyObject * s_python_function_fignum_exists
Definition: matplotlibcpp.h:52
~_interpreter()
Definition: matplotlibcpp.h:226
PyObject * s_python_function_subplot
Definition: matplotlibcpp.h:63
PyObject * s_python_function_xlim
Definition: matplotlibcpp.h:65
Definition: matplotlibcpp.h:1675
bool named_hist(std::string label, const std::vector< Numeric > &y, long bins=10, std::string color="b", double alpha=1.0)
Definition: matplotlibcpp.h:753
PyObject * s_python_function_title
Definition: matplotlibcpp.h:69
PyObject * s_python_function_tight_layout
Definition: matplotlibcpp.h:79
bool stem(const std::vector< Numeric > &x, const std::vector< Numeric > &y, const std::map< std::string, std::string > &keywords)
Definition: matplotlibcpp.h:458
typename std::is_function< std::remove_pointer< std::remove_reference< T > >>::type is_function
Definition: matplotlibcpp.h:1643
void close()
Definition: matplotlibcpp.h:1509
PyObject * s_python_function_ginput
Definition: matplotlibcpp.h:67
PyObject * s_python_function_stem
Definition: matplotlibcpp.h:82
bool clear()
Definition: matplotlibcpp.h:1836
bool hist(const std::vector< Numeric > &y, long bins=10, std::string color="b", double alpha=1.0, bool cumulative=false)
Definition: matplotlibcpp.h:553
void figure_size(size_t w, size_t h)
Definition: matplotlibcpp.h:1172
is_callable_impl< std::is_class< T >::value, T >::type type
Definition: matplotlibcpp.h:1678
bool plot(const std::vector< Numeric > &x, const std::vector< Numeric > &y, const std::map< std::string, std::string > &keywords)
Definition: matplotlibcpp.h:336
bool semilogx(const std::vector< NumericX > &x, const std::vector< NumericY > &y, const std::string &s="")
Definition: matplotlibcpp.h:859
bool quiver(const std::vector< NumericX > &x, const std::vector< NumericY > &y, const std::vector< NumericU > &u, const std::vector< NumericW > &w, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:800
bool semilogy(const std::vector< NumericX > &x, const std::vector< NumericY > &y, const std::string &s="")
Definition: matplotlibcpp.h:882
PyObject * s_python_function_annotate
Definition: matplotlibcpp.h:78
void backend(const std::string &name)
Definition: matplotlibcpp.h:234
PyObject * s_python_function_errorbar
Definition: matplotlibcpp.h:77
PyObject * s_python_function_ion
Definition: matplotlibcpp.h:66
_interpreter()
Definition: matplotlibcpp.h:132
PyObject * s_python_function_close
Definition: matplotlibcpp.h:47
PyObject * s_python_function_bar
Definition: matplotlibcpp.h:86
void legend()
Definition: matplotlibcpp.h:1195
Definition: matplotlibcpp.h:265
PyObject * safe_import(PyObject *module, std::string fname)
Definition: matplotlibcpp.h:101
bool fill(const std::vector< Numeric > &x, const std::vector< Numeric > &y, const std::map< std::string, std::string > &keywords)
Definition: matplotlibcpp.h:491
Definition: matplotlibcpp.h:1682
static _interpreter & get()
Definition: matplotlibcpp.h:96
bool errorbar(const std::vector< NumericX > &x, const std::vector< NumericY > &y, const std::vector< NumericX > &yerr, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:928
long figure(long number=-1)
Definition: matplotlibcpp.h:1126
void show(const bool block=true)
Definition: matplotlibcpp.h:1486
PyObject * s_python_function_pause
Definition: matplotlibcpp.h:49
bool operator()(const IterableX &x, const IterableY &y, const std::string &format)
Definition: matplotlibcpp.h:1688
bool update(const std::vector< Numeric > &x, const std::vector< Numeric > &y)
Definition: matplotlibcpp.h:1817
bool named_semilogy(const std::string &name, const std::vector< Numeric > &x, const std::vector< Numeric > &y, const std::string &format="")
Definition: matplotlibcpp.h:1037
PyObject * s_python_function_plot
Definition: matplotlibcpp.h:53
std::vector< std::array< double, 2 > > ginput(const int numClicks=1, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:1593
PyObject * s_python_function_yticks
Definition: matplotlibcpp.h:74
PyObject * s_python_function_fill_between
Definition: matplotlibcpp.h:59
Definition: matplotlibcpp.h:1685
PyObject * s_python_function_fill
Definition: matplotlibcpp.h:58
PyObject * s_python_function_save
Definition: matplotlibcpp.h:50
PyObject * s_python_function_figure
Definition: matplotlibcpp.h:51
Definition: matplotlibcpp.h:40
PyObject * s_python_function_subplots_adjust
Definition: matplotlibcpp.h:87
bool subplots_adjust(const std::map< std::string, double > &keywords={})
Definition: matplotlibcpp.h:730
Definition: matplotlibcpp.h:45
bool bar(const std::vector< Numeric > &x, const std::vector< Numeric > &y, std::string ec="black", std::string ls="-", double lw=1.0, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:679
PyObject * s_python_function_legend
Definition: matplotlibcpp.h:64
PyObject * s_python_function_axis
Definition: matplotlibcpp.h:70
bool named_semilogx(const std::string &name, const std::vector< Numeric > &x, const std::vector< Numeric > &y, const std::string &format="")
Definition: matplotlibcpp.h:1012
Definition: matplotlibcpp.h:1771
PyObject * s_python_function_imshow
Definition: matplotlibcpp.h:61
bool annotate(std::string annotation, double x, double y)
Definition: matplotlibcpp.h:239
void suptitle(const std::string &suptitlestr, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:1401
PyObject * s_python_function_quiver
Definition: matplotlibcpp.h:54
PyObject * s_python_function_semilogx
Definition: matplotlibcpp.h:55
void pause(Numeric interval)
Definition: matplotlibcpp.h:1547
void xlim(Numeric left, Numeric right)
Definition: matplotlibcpp.h:1221
PyObject * s_python_function_semilogy
Definition: matplotlibcpp.h:56
void text(Numeric x, Numeric y, const std::string &s="")
Definition: matplotlibcpp.h:1111
void import_numpy()
Definition: matplotlibcpp.h:125
PyObject * s_python_function_xticks
Definition: matplotlibcpp.h:73
PyObject * s_python_function_loglog
Definition: matplotlibcpp.h:57
void clf()
Definition: matplotlibcpp.h:1573
PyObject * s_python_function_xkcd
Definition: matplotlibcpp.h:83
void decref()
Definition: matplotlibcpp.h:1857
void xlabel(const std::string &str, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:1433
PyObject * s_python_function_hist
Definition: matplotlibcpp.h:60
bool named_loglog(const std::string &name, const std::vector< Numeric > &x, const std::vector< Numeric > &y, const std::string &format="")
Definition: matplotlibcpp.h:1062
PyObject * s_python_function_draw
Definition: matplotlibcpp.h:48
PyObject * s_python_function_ylabel
Definition: matplotlibcpp.h:72
void ion()
Definition: matplotlibcpp.h:1583
bool operator()(const Iterable &ticks, const Callable &f, const std::string &format)
Definition: matplotlibcpp.h:1727
void imshow(void *ptr, const NPY_TYPES type, const int rows, const int columns, const int colors, const std::map< std::string, std::string > &keywords)
Definition: matplotlibcpp.h:582
void subplot(long nrows, long ncols, long plot_number)
Definition: matplotlibcpp.h:1367
void title(const std::string &titlestr, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:1382
void save(const std::string &filename)
Definition: matplotlibcpp.h:1559
void ylabel(const std::string &str, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:1452
void axis(const std::string &axisstr)
Definition: matplotlibcpp.h:1420
bool loglog(const std::vector< NumericX > &x, const std::vector< NumericY > &y, const std::string &s="")
Definition: matplotlibcpp.h:905
void imshow(const unsigned char *ptr, const int rows, const int columns, const int colors, const std::map< std::string, std::string > &keywords={})
Definition: matplotlibcpp.h:610
PyObject * s_python_function_suptitle
Definition: matplotlibcpp.h:85
void draw()
Definition: matplotlibcpp.h:1535
Plot(const std::string &name, const std::vector< Numeric > &x, const std::vector< Numeric > &y, const std::string &format="")
Definition: matplotlibcpp.h:1776
void tight_layout()
Definition: matplotlibcpp.h:1628
~Plot()
Definition: matplotlibcpp.h:1852
is_function< T > type
Definition: matplotlibcpp.h:1651
PyObject * get_array(const std::vector< Numeric > &v)
Definition: matplotlibcpp.h:279
PyObject * get_2darray(const std::vector<::std::vector< Numeric >> &v)
Definition: matplotlibcpp.h:298
bool fill_between(const std::vector< Numeric > &x, const std::vector< Numeric > &y1, const std::vector< Numeric > &y2, const std::map< std::string, std::string > &keywords)
Definition: matplotlibcpp.h:521
bool scatter(const std::vector< NumericX > &x, const std::vector< NumericY > &y, const double s=1.0)
Definition: matplotlibcpp.h:653
Definition: matplotlibcpp.h:1646
PyObject * s_python_function_scatter
Definition: matplotlibcpp.h:62
PyObject * s_python_empty_tuple
Definition: matplotlibcpp.h:81