@@ -45,6 +45,7 @@ namespace detail {
45
45
static std::string s_backend;
46
46
47
47
struct _interpreter {
48
+ PyObject* s_python_function_arrow;
48
49
PyObject *s_python_function_show;
49
50
PyObject *s_python_function_close;
50
51
PyObject *s_python_function_draw;
@@ -54,6 +55,7 @@ struct _interpreter {
54
55
PyObject *s_python_function_fignum_exists;
55
56
PyObject *s_python_function_plot;
56
57
PyObject *s_python_function_quiver;
58
+ PyObject* s_python_function_contour;
57
59
PyObject *s_python_function_semilogx;
58
60
PyObject *s_python_function_semilogy;
59
61
PyObject *s_python_function_loglog;
@@ -79,8 +81,10 @@ struct _interpreter {
79
81
PyObject *s_python_function_gca;
80
82
PyObject *s_python_function_xticks;
81
83
PyObject *s_python_function_yticks;
84
+ PyObject* s_python_function_margins;
82
85
PyObject *s_python_function_tick_params;
83
86
PyObject *s_python_function_grid;
87
+ PyObject* s_python_function_cla;
84
88
PyObject *s_python_function_clf;
85
89
PyObject *s_python_function_errorbar;
86
90
PyObject *s_python_function_annotate;
@@ -186,6 +190,7 @@ struct _interpreter {
186
190
Py_DECREF (pylabname);
187
191
if (!pylabmod) { throw std::runtime_error (" Error loading module pylab!" ); }
188
192
193
+ s_python_function_arrow = safe_import (pymod, " arrow" );
189
194
s_python_function_show = safe_import (pymod, " show" );
190
195
s_python_function_close = safe_import (pymod, " close" );
191
196
s_python_function_draw = safe_import (pymod, " draw" );
@@ -194,6 +199,7 @@ struct _interpreter {
194
199
s_python_function_fignum_exists = safe_import (pymod, " fignum_exists" );
195
200
s_python_function_plot = safe_import (pymod, " plot" );
196
201
s_python_function_quiver = safe_import (pymod, " quiver" );
202
+ s_python_function_contour = safe_import (pymod, " contour" );
197
203
s_python_function_semilogx = safe_import (pymod, " semilogx" );
198
204
s_python_function_semilogy = safe_import (pymod, " semilogy" );
199
205
s_python_function_loglog = safe_import (pymod, " loglog" );
@@ -215,13 +221,15 @@ struct _interpreter {
215
221
s_python_function_gca = safe_import (pymod, " gca" );
216
222
s_python_function_xticks = safe_import (pymod, " xticks" );
217
223
s_python_function_yticks = safe_import (pymod, " yticks" );
224
+ s_python_function_margins = safe_import (pymod, " margins" );
218
225
s_python_function_tick_params = safe_import (pymod, " tick_params" );
219
226
s_python_function_grid = safe_import (pymod, " grid" );
220
227
s_python_function_xlim = safe_import (pymod, " xlim" );
221
228
s_python_function_ion = safe_import (pymod, " ion" );
222
229
s_python_function_ginput = safe_import (pymod, " ginput" );
223
230
s_python_function_save = safe_import (pylabmod, " savefig" );
224
231
s_python_function_annotate = safe_import (pymod," annotate" );
232
+ s_python_function_cla = safe_import (pymod, " cla" );
225
233
s_python_function_clf = safe_import (pymod, " clf" );
226
234
s_python_function_errorbar = safe_import (pymod, " errorbar" );
227
235
s_python_function_tight_layout = safe_import (pymod, " tight_layout" );
@@ -709,6 +717,37 @@ bool fill_between(const std::vector<Numeric>& x, const std::vector<Numeric>& y1,
709
717
return res;
710
718
}
711
719
720
+ template <typename Numeric>
721
+ bool arrow (Numeric x, Numeric y, Numeric end_x, Numeric end_y, const std::string& fc = " r" ,
722
+ const std::string ec = " k" , Numeric head_length = 0.25 , Numeric head_width = 0.1625 ) {
723
+ PyObject* obj_x = PyFloat_FromDouble (x);
724
+ PyObject* obj_y = PyFloat_FromDouble (y);
725
+ PyObject* obj_end_x = PyFloat_FromDouble (end_x);
726
+ PyObject* obj_end_y = PyFloat_FromDouble (end_y);
727
+
728
+ PyObject* kwargs = PyDict_New ();
729
+ PyDict_SetItemString (kwargs, " fc" , PyString_FromString (fc.c_str ()));
730
+ PyDict_SetItemString (kwargs, " ec" , PyString_FromString (ec.c_str ()));
731
+ PyDict_SetItemString (kwargs, " head_width" , PyFloat_FromDouble (head_width));
732
+ PyDict_SetItemString (kwargs, " head_length" , PyFloat_FromDouble (head_length));
733
+
734
+ PyObject* plot_args = PyTuple_New (4 );
735
+ PyTuple_SetItem (plot_args, 0 , obj_x);
736
+ PyTuple_SetItem (plot_args, 1 , obj_y);
737
+ PyTuple_SetItem (plot_args, 2 , obj_end_x);
738
+ PyTuple_SetItem (plot_args, 3 , obj_end_y);
739
+
740
+ PyObject* res =
741
+ PyObject_Call (detail::_interpreter::get ().s_python_function_arrow , plot_args, kwargs);
742
+
743
+ Py_DECREF (plot_args);
744
+ Py_DECREF (kwargs);
745
+ if (res)
746
+ Py_DECREF (res);
747
+
748
+ return res;
749
+ }
750
+
712
751
template < typename Numeric>
713
752
bool hist (const std::vector<Numeric>& y, long bins=10 ,std::string color=" b" ,
714
753
double alpha=1.0 , bool cumulative=false )
@@ -1040,6 +1079,39 @@ bool plot(const std::vector<NumericX>& x, const std::vector<NumericY>& y, const
1040
1079
return res;
1041
1080
}
1042
1081
1082
+ template <typename NumericX, typename NumericY, typename NumericZ>
1083
+ bool contour (const std::vector<NumericX>& x, const std::vector<NumericY>& y,
1084
+ const std::vector<NumericZ>& z,
1085
+ const std::map<std::string, std::string>& keywords = {}) {
1086
+ assert (x.size () == y.size () && x.size () == z.size ());
1087
+
1088
+ PyObject* xarray = get_array (x);
1089
+ PyObject* yarray = get_array (y);
1090
+ PyObject* zarray = get_array (z);
1091
+
1092
+ PyObject* plot_args = PyTuple_New (3 );
1093
+ PyTuple_SetItem (plot_args, 0 , xarray);
1094
+ PyTuple_SetItem (plot_args, 1 , yarray);
1095
+ PyTuple_SetItem (plot_args, 2 , zarray);
1096
+
1097
+ // construct keyword args
1098
+ PyObject* kwargs = PyDict_New ();
1099
+ for (std::map<std::string, std::string>::const_iterator it = keywords.begin ();
1100
+ it != keywords.end (); ++it) {
1101
+ PyDict_SetItemString (kwargs, it->first .c_str (), PyUnicode_FromString (it->second .c_str ()));
1102
+ }
1103
+
1104
+ PyObject* res =
1105
+ PyObject_Call (detail::_interpreter::get ().s_python_function_contour , plot_args, kwargs);
1106
+
1107
+ Py_DECREF (kwargs);
1108
+ Py_DECREF (plot_args);
1109
+ if (res)
1110
+ Py_DECREF (res);
1111
+
1112
+ return res;
1113
+ }
1114
+
1043
1115
template <typename NumericX, typename NumericY, typename NumericU, typename NumericW>
1044
1116
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 = {})
1045
1117
{
@@ -1669,6 +1741,38 @@ inline void yticks(const std::vector<Numeric> &ticks, const std::map<std::string
1669
1741
yticks (ticks, {}, keywords);
1670
1742
}
1671
1743
1744
+ template <typename Numeric> inline void margins (Numeric margin)
1745
+ {
1746
+ // construct positional args
1747
+ PyObject* args = PyTuple_New (1 );
1748
+ PyTuple_SetItem (args, 0 , PyFloat_FromDouble (margin));
1749
+
1750
+ PyObject* res =
1751
+ PyObject_CallObject (detail::_interpreter::get ().s_python_function_margins , args);
1752
+ if (!res)
1753
+ throw std::runtime_error (" Call to margins() failed." );
1754
+
1755
+ Py_DECREF (args);
1756
+ Py_DECREF (res);
1757
+ }
1758
+
1759
+ template <typename Numeric> inline void margins (Numeric margin_x, Numeric margin_y)
1760
+ {
1761
+ // construct positional args
1762
+ PyObject* args = PyTuple_New (2 );
1763
+ PyTuple_SetItem (args, 0 , PyFloat_FromDouble (margin_x));
1764
+ PyTuple_SetItem (args, 1 , PyFloat_FromDouble (margin_y));
1765
+
1766
+ PyObject* res =
1767
+ PyObject_CallObject (detail::_interpreter::get ().s_python_function_margins , args);
1768
+ if (!res)
1769
+ throw std::runtime_error (" Call to margins() failed." );
1770
+
1771
+ Py_DECREF (args);
1772
+ Py_DECREF (res);
1773
+ }
1774
+
1775
+
1672
1776
inline void tick_params (const std::map<std::string, std::string>& keywords, const std::string axis = " both" )
1673
1777
{
1674
1778
detail::_interpreter::get ();
@@ -2069,6 +2173,18 @@ inline void clf() {
2069
2173
Py_DECREF (res);
2070
2174
}
2071
2175
2176
+ inline void cla () {
2177
+ detail::_interpreter::get ();
2178
+
2179
+ PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_cla ,
2180
+ detail::_interpreter::get ().s_python_empty_tuple );
2181
+
2182
+ if (!res)
2183
+ throw std::runtime_error (" Call to cla() failed." );
2184
+
2185
+ Py_DECREF (res);
2186
+ }
2187
+
2072
2188
inline void ion () {
2073
2189
detail::_interpreter::get ();
2074
2190
0 commit comments