@@ -103,7 +103,6 @@ struct _interpreter {
103
103
PyObject *s_python_function_subplots_adjust;
104
104
PyObject *s_python_function_rcparams;
105
105
106
-
107
106
/* For now, _interpreter is implemented as a singleton since its currently not possible to have
108
107
multiple independent embedded python interpreters without patching the python source code
109
108
or starting a separate process for each. [1]
@@ -245,6 +244,7 @@ struct _interpreter {
245
244
s_python_function_subplot = safe_import (pymod, " subplot" );
246
245
s_python_function_subplot2grid = safe_import (pymod, " subplot2grid" );
247
246
s_python_function_legend = safe_import (pymod, " legend" );
247
+ s_python_function_xlim = safe_import (pymod, " xlim" );
248
248
s_python_function_ylim = safe_import (pymod, " ylim" );
249
249
s_python_function_title = safe_import (pymod, " title" );
250
250
s_python_function_axis = safe_import (pymod, " axis" );
@@ -259,7 +259,6 @@ struct _interpreter {
259
259
s_python_function_margins = safe_import (pymod, " margins" );
260
260
s_python_function_tick_params = safe_import (pymod, " tick_params" );
261
261
s_python_function_grid = safe_import (pymod, " grid" );
262
- s_python_function_xlim = safe_import (pymod, " xlim" );
263
262
s_python_function_ion = safe_import (pymod, " ion" );
264
263
s_python_function_ginput = safe_import (pymod, " ginput" );
265
264
s_python_function_save = safe_import (pylabmod, " savefig" );
@@ -349,10 +348,10 @@ template <> struct select_npy_type<uint64_t> { const static NPY_TYPES type = NPY
349
348
350
349
// Sanity checks; comment them out or change the numpy type below if you're compiling on
351
350
// a platform where they don't apply
352
- static_assert (sizeof (long long ) == 8);
353
- template <> struct select_npy_type <long long > { const static NPY_TYPES type = NPY_INT64; };
354
- static_assert (sizeof (unsigned long long ) == 8);
355
- template <> struct select_npy_type <unsigned long long > { const static NPY_TYPES type = NPY_UINT64; };
351
+ // static_assert(sizeof(long long) == 8);
352
+ // template <> struct select_npy_type<long long> { const static NPY_TYPES type = NPY_INT64; };
353
+ // static_assert(sizeof(unsigned long long) == 8);
354
+ // template <> struct select_npy_type<unsigned long long> { const static NPY_TYPES type = NPY_UINT64; };
356
355
// TODO: add int, long, etc.
357
356
358
357
template <typename Numeric>
@@ -582,6 +581,49 @@ void plot_surface(const std::vector<::std::vector<Numeric>> &x,
582
581
Py_DECREF (kwargs);
583
582
if (res) Py_DECREF (res);
584
583
}
584
+
585
+ template <typename Numeric>
586
+ void contour (const std::vector<::std::vector<Numeric>> &x,
587
+ const std::vector<::std::vector<Numeric>> &y,
588
+ const std::vector<::std::vector<Numeric>> &z,
589
+ const std::map<std::string, std::string> &keywords = {})
590
+ {
591
+ detail::_interpreter::get ();
592
+
593
+ // using numpy arrays
594
+ PyObject *xarray = detail::get_2darray (x);
595
+ PyObject *yarray = detail::get_2darray (y);
596
+ PyObject *zarray = detail::get_2darray (z);
597
+
598
+ // construct positional args
599
+ PyObject *args = PyTuple_New (3 );
600
+ PyTuple_SetItem (args, 0 , xarray);
601
+ PyTuple_SetItem (args, 1 , yarray);
602
+ PyTuple_SetItem (args, 2 , zarray);
603
+
604
+ // Build up the kw args.
605
+ PyObject *kwargs = PyDict_New ();
606
+
607
+ PyObject *python_colormap_coolwarm = PyObject_GetAttrString (
608
+ detail::_interpreter::get ().s_python_colormap , " coolwarm" );
609
+
610
+ PyDict_SetItemString (kwargs, " cmap" , python_colormap_coolwarm);
611
+
612
+ for (std::map<std::string, std::string>::const_iterator it = keywords.begin ();
613
+ it != keywords.end (); ++it) {
614
+ PyDict_SetItemString (kwargs, it->first .c_str (),
615
+ PyString_FromString (it->second .c_str ()));
616
+ }
617
+
618
+ PyObject *res = PyObject_Call (detail::_interpreter::get ().s_python_function_contour , args, kwargs);
619
+ if (!res)
620
+ throw std::runtime_error (" failed contour" );
621
+
622
+ Py_DECREF (args);
623
+ Py_DECREF (kwargs);
624
+ if (res)
625
+ Py_DECREF (res);
626
+ }
585
627
#endif // WITHOUT_NUMPY
586
628
587
629
template <typename Numeric>
0 commit comments