@@ -127,29 +127,29 @@ namespace matplotlibcpp {
127
127
};
128
128
}
129
129
130
- bool annotate (std::string annotation, double x, double y)
131
- {
132
- PyObject * xy = PyTuple_New (2 );
133
- PyObject * str = PyString_FromString (annotation.c_str ());
134
-
135
- PyTuple_SetItem (xy,0 ,PyFloat_FromDouble (x));
136
- PyTuple_SetItem (xy,1 ,PyFloat_FromDouble (y));
137
-
138
- PyObject* kwargs = PyDict_New ();
139
- PyDict_SetItemString (kwargs, " xy" , xy);
140
-
130
+ bool annotate (std::string annotation, double x, double y)
131
+ {
132
+ PyObject * xy = PyTuple_New (2 );
133
+ PyObject * str = PyString_FromString (annotation.c_str ());
134
+
135
+ PyTuple_SetItem (xy,0 ,PyFloat_FromDouble (x));
136
+ PyTuple_SetItem (xy,1 ,PyFloat_FromDouble (y));
137
+
138
+ PyObject* kwargs = PyDict_New ();
139
+ PyDict_SetItemString (kwargs, " xy" , xy);
140
+
141
141
PyObject* args = PyTuple_New (1 );
142
142
PyTuple_SetItem (args, 0 , str);
143
143
144
- PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_annotate , args, kwargs);
144
+ PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_annotate , args, kwargs);
145
145
146
146
Py_DECREF (args);
147
147
Py_DECREF (kwargs);
148
148
149
149
if (res) Py_DECREF (res);
150
150
151
151
return res;
152
- }
152
+ }
153
153
154
154
template <typename Numeric>
155
155
bool plot (const std::vector<Numeric> &x, const std::vector<Numeric> &y, const std::map<std::string, std::string>& keywords)
@@ -187,14 +187,14 @@ namespace matplotlibcpp {
187
187
}
188
188
189
189
template < typename Numeric>
190
- bool hist (const std::vector<Numeric>& y, long bins=10 ,std::string color=" b" , double alpha=1.0 ){
191
-
190
+ bool hist (const std::vector<Numeric>& y, long bins=10 ,std::string color=" b" , double alpha=1.0 )
191
+ {
192
192
PyObject* ylist = PyList_New (y.size ());
193
193
194
194
PyObject* kwargs = PyDict_New ();
195
195
PyDict_SetItemString (kwargs, " bins" , PyLong_FromLong (bins));
196
- PyDict_SetItemString (kwargs, " color" , PyString_FromString (color.c_str ()));
197
- PyDict_SetItemString (kwargs, " alpha" , PyFloat_FromDouble (alpha));
196
+ PyDict_SetItemString (kwargs, " color" , PyString_FromString (color.c_str ()));
197
+ PyDict_SetItemString (kwargs, " alpha" , PyFloat_FromDouble (alpha));
198
198
199
199
for (size_t i = 0 ; i < y.size (); ++i) {
200
200
PyList_SetItem (ylist, i, PyFloat_FromDouble (y.at (i)));
@@ -214,9 +214,10 @@ namespace matplotlibcpp {
214
214
215
215
return res;
216
216
}
217
- template < typename Numeric>
218
- bool named_hist (std::string label,const std::vector<Numeric>& y, long bins=10 ,std::string color=" b" , double alpha=1.0 ){
219
217
218
+ template < typename Numeric>
219
+ bool named_hist (std::string label,const std::vector<Numeric>& y, long bins=10 , std::string color=" b" , double alpha=1.0 )
220
+ {
220
221
PyObject* ylist = PyList_New (y.size ());
221
222
PyObject* kwargs = PyDict_New ();
222
223
PyDict_SetItemString (kwargs, " label" , PyString_FromString (label.c_str ()));
@@ -233,7 +234,6 @@ namespace matplotlibcpp {
233
234
234
235
PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_hist , plot_args, kwargs);
235
236
236
-
237
237
Py_DECREF (plot_args);
238
238
Py_DECREF (kwargs);
239
239
if (res) Py_DECREF (res);
@@ -269,7 +269,8 @@ namespace matplotlibcpp {
269
269
}
270
270
271
271
template <typename NumericX, typename NumericY>
272
- bool errorbar (const std::vector<NumericX> &x, const std::vector<NumericY> &y, const std::vector<NumericX> &yerr, const std::string &s = " " ) {
272
+ bool errorbar (const std::vector<NumericX> &x, const std::vector<NumericY> &y, const std::vector<NumericX> &yerr, const std::string &s = " " )
273
+ {
273
274
assert (x.size () == y.size ());
274
275
275
276
PyObject *kwargs = PyDict_New ();
@@ -307,7 +308,8 @@ namespace matplotlibcpp {
307
308
}
308
309
309
310
template <typename Numeric>
310
- bool named_plot (const std::string& name, const std::vector<Numeric>& y, const std::string& format = " " ) {
311
+ bool named_plot (const std::string& name, const std::vector<Numeric>& y, const std::string& format = " " )
312
+ {
311
313
PyObject* kwargs = PyDict_New ();
312
314
PyDict_SetItemString (kwargs, " label" , PyString_FromString (name.c_str ()));
313
315
@@ -333,7 +335,8 @@ namespace matplotlibcpp {
333
335
}
334
336
335
337
template <typename Numeric>
336
- bool named_plot (const std::string& name, const std::vector<Numeric>& x, const std::vector<Numeric>& y, const std::string& format = " " ) {
338
+ bool named_plot (const std::string& name, const std::vector<Numeric>& x, const std::vector<Numeric>& y, const std::string& format = " " )
339
+ {
337
340
PyObject* kwargs = PyDict_New ();
338
341
PyDict_SetItemString (kwargs, " label" , PyString_FromString (name.c_str ()));
339
342
@@ -368,14 +371,16 @@ namespace matplotlibcpp {
368
371
return plot (x,y,format);
369
372
}
370
373
371
- inline void figure (){
374
+ inline void figure ()
375
+ {
372
376
PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_figure , detail::_interpreter::get ().s_python_empty_tuple );
373
377
if (!res) throw std::runtime_error (" Call to figure() failed." );
374
378
375
379
Py_DECREF (res);
376
-
377
- }
378
- inline void legend () {
380
+ }
381
+
382
+ inline void legend ()
383
+ {
379
384
PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_legend , detail::_interpreter::get ().s_python_empty_tuple );
380
385
if (!res) throw std::runtime_error (" Call to legend() failed." );
381
386
@@ -417,50 +422,55 @@ namespace matplotlibcpp {
417
422
}
418
423
419
424
420
- double * xlim ()
421
- {
422
- PyObject* args = PyTuple_New (0 );
425
+ inline double * xlim ()
426
+ {
427
+ PyObject* args = PyTuple_New (0 );
423
428
PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_xlim , args);
424
- PyObject * left = PyTuple_GetItem (res,0 );
425
- PyObject * right = PyTuple_GetItem (res,1 );
426
- double * arr = new double [2 ];
427
- arr[0 ] = PyFloat_AsDouble (left);
428
- arr[1 ] = PyFloat_AsDouble (right);
429
+ PyObject* left = PyTuple_GetItem (res,0 );
430
+ PyObject* right = PyTuple_GetItem (res,1 );
431
+
432
+ double * arr = new double [2 ];
433
+ arr[0 ] = PyFloat_AsDouble (left);
434
+ arr[1 ] = PyFloat_AsDouble (right);
429
435
430
- if (!res) throw std::runtime_error (" Call to xlim() failed." );
431
- Py_DECREF (res);
432
- return arr;
433
- }
436
+ if (!res) throw std::runtime_error (" Call to xlim() failed." );
437
+
438
+ Py_DECREF (res);
439
+ return arr;
440
+ }
434
441
435
442
436
- double * ylim ()
437
- {
438
- PyObject* args = PyTuple_New (0 );
443
+ inline double * ylim ()
444
+ {
445
+ PyObject* args = PyTuple_New (0 );
439
446
PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_ylim , args);
440
- PyObject * left = PyTuple_GetItem (res,0 );
441
- PyObject * right = PyTuple_GetItem (res,1 );
442
- double * arr = new double [2 ];
443
- arr[0 ] = PyFloat_AsDouble (left);
444
- arr[1 ] = PyFloat_AsDouble (right);
447
+ PyObject* left = PyTuple_GetItem (res,0 );
448
+ PyObject* right = PyTuple_GetItem (res,1 );
449
+
450
+ double * arr = new double [2 ];
451
+ arr[0 ] = PyFloat_AsDouble (left);
452
+ arr[1 ] = PyFloat_AsDouble (right);
445
453
446
454
if (!res) throw std::runtime_error (" Call to ylim() failed." );
447
- Py_DECREF (res);
448
- return arr;
449
- }
450
455
451
- inline void subplot (long nrows, long ncols, long plot_number) {
452
- // construct positional args
453
- PyObject* args = PyTuple_New (3 );
454
- PyTuple_SetItem (args, 0 , PyFloat_FromDouble (nrows));
455
- PyTuple_SetItem (args, 1 , PyFloat_FromDouble (ncols));
456
- PyTuple_SetItem (args, 2 , PyFloat_FromDouble (plot_number));
456
+ Py_DECREF (res);
457
+ return arr;
458
+ }
459
+
460
+ inline void subplot (long nrows, long ncols, long plot_number)
461
+ {
462
+ // construct positional args
463
+ PyObject* args = PyTuple_New (3 );
464
+ PyTuple_SetItem (args, 0 , PyFloat_FromDouble (nrows));
465
+ PyTuple_SetItem (args, 1 , PyFloat_FromDouble (ncols));
466
+ PyTuple_SetItem (args, 2 , PyFloat_FromDouble (plot_number));
457
467
458
- PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_subplot , args);
459
- if (!res) throw std::runtime_error (" Call to subplot() failed." );
468
+ PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_subplot , args);
469
+ if (!res) throw std::runtime_error (" Call to subplot() failed." );
460
470
461
- Py_DECREF (args);
462
- Py_DECREF (res);
463
- }
471
+ Py_DECREF (args);
472
+ Py_DECREF (res);
473
+ }
464
474
465
475
inline void title (const std::string &titlestr)
466
476
{
@@ -474,7 +484,7 @@ namespace matplotlibcpp {
474
484
// if PyDeCRFF, the function doesn't work on Mac OS
475
485
}
476
486
477
- inline void axis (const std::string &axisstr)
487
+ inline void axis (const std::string &axisstr)
478
488
{
479
489
PyObject* str = PyString_FromString (axisstr.c_str ());
480
490
PyObject* args = PyTuple_New (1 );
@@ -486,7 +496,7 @@ namespace matplotlibcpp {
486
496
// if PyDeCRFF, the function doesn't work on Mac OS
487
497
}
488
498
489
- inline void xlabel (const std::string &str)
499
+ inline void xlabel (const std::string &str)
490
500
{
491
501
PyObject* pystr = PyString_FromString (str.c_str ());
492
502
PyObject* args = PyTuple_New (1 );
@@ -498,7 +508,7 @@ namespace matplotlibcpp {
498
508
// if PyDeCRFF, the function doesn't work on Mac OS
499
509
}
500
510
501
- inline void ylabel (const std::string &str)
511
+ inline void ylabel (const std::string &str)
502
512
{
503
513
PyObject* pystr = PyString_FromString (str.c_str ());
504
514
PyObject* args = PyTuple_New (1 );
@@ -510,7 +520,7 @@ namespace matplotlibcpp {
510
520
// if PyDeCRFF, the function doesn't work on Mac OS
511
521
}
512
522
513
- inline void grid (bool flag)
523
+ inline void grid (bool flag)
514
524
{
515
525
PyObject* pyflag = flag ? Py_True : Py_False;
516
526
@@ -525,8 +535,11 @@ namespace matplotlibcpp {
525
535
526
536
inline void show ()
527
537
{
528
- PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_show , detail::_interpreter::get ().s_python_empty_tuple );
529
- if (!res) throw std::runtime_error (" Call to show() failed." );
538
+ PyObject* res = PyObject_CallObject (
539
+ detail::_interpreter::get ().s_python_function_show ,
540
+ detail::_interpreter::get ().s_python_empty_tuple );
541
+
542
+ if (!res) throw std::runtime_error (" Call to show() failed." );
530
543
531
544
Py_DECREF (res);
532
545
}
@@ -539,15 +552,17 @@ namespace matplotlibcpp {
539
552
PyTuple_SetItem (args, 0 , pyfilename);
540
553
541
554
PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_save , args);
542
- if (!res) throw std::runtime_error (" Call to save() failed." );
555
+ if (!res) throw std::runtime_error (" Call to save() failed." );
543
556
544
557
Py_DECREF (args);
545
558
Py_DECREF (res);
546
559
}
547
560
548
561
inline void clf () {
549
- PyObject *res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_clf ,
550
- detail::_interpreter::get ().s_python_empty_tuple );
562
+ PyObject *res = PyObject_CallObject (
563
+ detail::_interpreter::get ().s_python_function_clf ,
564
+ detail::_interpreter::get ().s_python_empty_tuple );
565
+
551
566
if (!res) throw std::runtime_error (" Call to clf() failed." );
552
567
553
568
Py_DECREF (res);
0 commit comments