@@ -32,8 +32,8 @@ namespace matplotlibcpp {
32
32
33
33
/* For now, _interpreter is implemented as a singleton since its currently not possible to have
34
34
multiple independent embedded python interpreters without patching the python source code
35
- or starting a seperate process for each.
36
-
35
+ or starting a separate process for each.
36
+
37
37
http://bytes.com/topic/python/answers/793370-multiple-independent-python-interpreters-c-c-program
38
38
*/
39
39
@@ -44,12 +44,12 @@ namespace matplotlibcpp {
44
44
45
45
private:
46
46
_interpreter () {
47
- char name[] = " plotting" ; // silence compiler warning abount const strings
47
+ char name[] = " plotting" ; // silence compiler warning about const strings
48
48
Py_SetProgramName (name); // optional but recommended
49
49
Py_Initialize ();
50
50
51
51
PyObject* pyplotname = PyString_FromString (" matplotlib.pyplot" );
52
- PyObject* pylabname = PyString_FromString (" pylab" );
52
+ PyObject* pylabname = PyString_FromString (" pylab" );
53
53
if (!pyplotname || !pylabname) { throw std::runtime_error (" couldnt create string" ); }
54
54
55
55
PyObject* pymod = PyImport_Import (pyplotname);
@@ -71,36 +71,35 @@ namespace matplotlibcpp {
71
71
s_python_function_ylabel = PyObject_GetAttrString (pymod, " ylabel" );
72
72
s_python_function_grid = PyObject_GetAttrString (pymod, " grid" );
73
73
s_python_function_xlim = PyObject_GetAttrString (pymod, " xlim" );
74
-
75
74
s_python_function_save = PyObject_GetAttrString (pylabmod, " savefig" );
76
75
77
- if (!s_python_function_show
78
- || !s_python_function_save
79
- || !s_python_function_figure
80
- || !s_python_function_plot
81
- || !s_python_function_legend
82
- || !s_python_function_xlim
76
+ if ( !s_python_function_show
77
+ || !s_python_function_figure
78
+ || !s_python_function_plot
79
+ || !s_python_function_legend
83
80
|| !s_python_function_ylim
84
81
|| !s_python_function_title
85
82
|| !s_python_function_axis
86
83
|| !s_python_function_xlabel
87
84
|| !s_python_function_ylabel
88
85
|| !s_python_function_grid
89
- )
90
- { throw std::runtime_error (" Couldnt find required function!" ); }
86
+ || !s_python_function_xlim
87
+ || !s_python_function_save
88
+ )
89
+ { throw std::runtime_error (" Couldn't find required function!" ); }
91
90
92
- if (!PyFunction_Check (s_python_function_show)
93
- || !PyFunction_Check (s_python_function_save)
91
+ if ( !PyFunction_Check (s_python_function_show)
94
92
|| !PyFunction_Check (s_python_function_figure)
95
93
|| !PyFunction_Check (s_python_function_plot)
96
- || !PyFunction_Check (s_python_function_legend)
97
- || !PyFunction_Check (s_python_function_xlim)
98
- || !PyFunction_Check (s_python_function_ylim)
94
+ || !PyFunction_Check (s_python_function_legend)
95
+ || !PyFunction_Check (s_python_function_ylim)
99
96
|| !PyFunction_Check (s_python_function_title)
100
97
|| !PyFunction_Check (s_python_function_axis)
101
98
|| !PyFunction_Check (s_python_function_xlabel)
102
99
|| !PyFunction_Check (s_python_function_ylabel)
103
100
|| !PyFunction_Check (s_python_function_grid)
101
+ || !PyFunction_Check (s_python_function_xlim)
102
+ || !PyFunction_Check (s_python_function_save)
104
103
)
105
104
{ throw std::runtime_error (" Python object is unexpectedly not a PyFunction." ); }
106
105
@@ -113,8 +112,6 @@ namespace matplotlibcpp {
113
112
};
114
113
}
115
114
116
-
117
-
118
115
template <typename Numeric>
119
116
bool plot (const std::vector<Numeric> &x, const std::vector<Numeric> &y, const std::map<std::string, std::string>& keywords)
120
117
{
@@ -153,7 +150,6 @@ namespace matplotlibcpp {
153
150
return res;
154
151
}
155
152
156
-
157
153
template <typename NumericX, typename NumericY>
158
154
bool plot (const std::vector<NumericX>& x, const std::vector<NumericY>& y, const std::string& s = " " )
159
155
{
@@ -183,7 +179,6 @@ namespace matplotlibcpp {
183
179
return res;
184
180
}
185
181
186
-
187
182
template <typename Numeric>
188
183
bool named_plot (const std::string& name, const std::vector<Numeric>& x, const std::vector<Numeric>& y, const std::string& format = " " ) {
189
184
PyObject* kwargs = PyDict_New ();
@@ -223,7 +218,7 @@ namespace matplotlibcpp {
223
218
}
224
219
225
220
226
- inline void legend () {
221
+ inline void legend () {
227
222
PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_legend , detail::_interpreter::get ().s_python_empty_tuple );
228
223
if (!res) throw std::runtime_error (" Call to legend() failed." );
229
224
@@ -266,7 +261,6 @@ namespace matplotlibcpp {
266
261
Py_DECREF (res);
267
262
}
268
263
269
-
270
264
inline void title (const std::string &titlestr)
271
265
{
272
266
PyObject* pytitlestr = PyString_FromString (titlestr.c_str ());
@@ -291,8 +285,6 @@ namespace matplotlibcpp {
291
285
// if PyDeCRFF, the function doesn't work on Mac OS
292
286
}
293
287
294
-
295
-
296
288
inline void xlabel (const std::string &str)
297
289
{
298
290
PyObject* pystr = PyString_FromString (str.c_str ());
@@ -330,8 +322,6 @@ namespace matplotlibcpp {
330
322
// if PyDeCRFF, the function doesn't work on Mac OS
331
323
}
332
324
333
-
334
-
335
325
inline void show ()
336
326
{
337
327
PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_show , detail::_interpreter::get ().s_python_empty_tuple );
@@ -368,7 +358,7 @@ namespace matplotlibcpp {
368
358
template <typename T>
369
359
struct is_callable_impl <false , T>
370
360
{
371
- typedef is_function<T> type;
361
+ typedef is_function<T> type;
372
362
}; // a non-object is callable iff it is a function
373
363
374
364
template <typename T>
@@ -452,10 +442,10 @@ namespace matplotlibcpp {
452
442
453
443
if (begin (ticks) == end (ticks)) return true ;
454
444
455
- // We could use additional meta-programming to deduce the correct element type of y,
445
+ // We could use additional meta-programming to deduce the correct element type of y,
456
446
// but all values have to be convertible to double anyways
457
447
std::vector<double > y;
458
- for (auto x : ticks) y.push_back (f (x));
448
+ for (auto x : ticks) y.push_back (f (x));
459
449
return plot_impl<std::false_type>()(ticks,y,format);
460
450
}
461
451
};
@@ -493,7 +483,4 @@ namespace matplotlibcpp {
493
483
494
484
#endif
495
485
496
-
497
-
498
-
499
486
}
0 commit comments