Skip to content

Commit 71bd59b

Browse files
flyvbeelava
authored andcommitted
added support to semilogx, semilogy, and loglog.
1 parent 687a42d commit 71bd59b

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

matplotlibcpp.h

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ namespace matplotlibcpp {
3636
PyObject *s_python_function_save;
3737
PyObject *s_python_function_figure;
3838
PyObject *s_python_function_plot;
39+
PyObject *s_python_function_semilogx;
40+
PyObject *s_python_function_semilogy;
41+
PyObject *s_python_function_loglog;
3942
PyObject *s_python_function_fill_between;
4043
PyObject *s_python_function_hist;
4144
PyObject *s_python_function_subplot;
@@ -111,6 +114,9 @@ namespace matplotlibcpp {
111114
s_python_function_pause = PyObject_GetAttrString(pymod, "pause");
112115
s_python_function_figure = PyObject_GetAttrString(pymod, "figure");
113116
s_python_function_plot = PyObject_GetAttrString(pymod, "plot");
117+
s_python_function_semilogx = PyObject_GetAttrString(pymod, "semilogx");
118+
s_python_function_semilogy = PyObject_GetAttrString(pymod, "semilogy");
119+
s_python_function_loglog = PyObject_GetAttrString(pymod, "loglog");
114120
s_python_function_fill_between = PyObject_GetAttrString(pymod, "fill_between");
115121
s_python_function_hist = PyObject_GetAttrString(pymod,"hist");
116122
s_python_function_subplot = PyObject_GetAttrString(pymod, "subplot");
@@ -133,6 +139,9 @@ namespace matplotlibcpp {
133139
|| !s_python_function_pause
134140
|| !s_python_function_figure
135141
|| !s_python_function_plot
142+
|| !s_python_function_semilogx
143+
|| !s_python_function_semilogy
144+
|| !s_python_function_loglog
136145
|| !s_python_function_fill_between
137146
|| !s_python_function_subplot
138147
|| !s_python_function_legend
@@ -156,6 +165,9 @@ namespace matplotlibcpp {
156165
|| !PyFunction_Check(s_python_function_pause)
157166
|| !PyFunction_Check(s_python_function_figure)
158167
|| !PyFunction_Check(s_python_function_plot)
168+
|| !PyFunction_Check(s_python_function_semilogx)
169+
|| !PyFunction_Check(s_python_function_semilogy)
170+
|| !PyFunction_Check(s_python_function_loglog)
159171
|| !PyFunction_Check(s_python_function_fill_between)
160172
|| !PyFunction_Check(s_python_function_subplot)
161173
|| !PyFunction_Check(s_python_function_legend)
@@ -397,6 +409,75 @@ namespace matplotlibcpp {
397409
return res;
398410
}
399411

412+
template<typename NumericX, typename NumericY>
413+
bool semilogx(const std::vector<NumericX>& x, const std::vector<NumericY>& y, const std::string& s = "")
414+
{
415+
assert(x.size() == y.size());
416+
417+
PyObject* xarray = get_array(x);
418+
PyObject* yarray = get_array(y);
419+
420+
PyObject* pystring = PyString_FromString(s.c_str());
421+
422+
PyObject* plot_args = PyTuple_New(3);
423+
PyTuple_SetItem(plot_args, 0, xarray);
424+
PyTuple_SetItem(plot_args, 1, yarray);
425+
PyTuple_SetItem(plot_args, 2, pystring);
426+
427+
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_semilogx, plot_args);
428+
429+
Py_DECREF(plot_args);
430+
if(res) Py_DECREF(res);
431+
432+
return res;
433+
}
434+
435+
template<typename NumericX, typename NumericY>
436+
bool semilogy(const std::vector<NumericX>& x, const std::vector<NumericY>& y, const std::string& s = "")
437+
{
438+
assert(x.size() == y.size());
439+
440+
PyObject* xarray = get_array(x);
441+
PyObject* yarray = get_array(y);
442+
443+
PyObject* pystring = PyString_FromString(s.c_str());
444+
445+
PyObject* plot_args = PyTuple_New(3);
446+
PyTuple_SetItem(plot_args, 0, xarray);
447+
PyTuple_SetItem(plot_args, 1, yarray);
448+
PyTuple_SetItem(plot_args, 2, pystring);
449+
450+
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_semilogy, plot_args);
451+
452+
Py_DECREF(plot_args);
453+
if(res) Py_DECREF(res);
454+
455+
return res;
456+
}
457+
458+
template<typename NumericX, typename NumericY>
459+
bool loglog(const std::vector<NumericX>& x, const std::vector<NumericY>& y, const std::string& s = "")
460+
{
461+
assert(x.size() == y.size());
462+
463+
PyObject* xarray = get_array(x);
464+
PyObject* yarray = get_array(y);
465+
466+
PyObject* pystring = PyString_FromString(s.c_str());
467+
468+
PyObject* plot_args = PyTuple_New(3);
469+
PyTuple_SetItem(plot_args, 0, xarray);
470+
PyTuple_SetItem(plot_args, 1, yarray);
471+
PyTuple_SetItem(plot_args, 2, pystring);
472+
473+
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_loglog, plot_args);
474+
475+
Py_DECREF(plot_args);
476+
if(res) Py_DECREF(res);
477+
478+
return res;
479+
}
480+
400481
template<typename NumericX, typename NumericY>
401482
bool errorbar(const std::vector<NumericX> &x, const std::vector<NumericY> &y, const std::vector<NumericX> &yerr, const std::string &s = "")
402483
{
@@ -478,6 +559,81 @@ namespace matplotlibcpp {
478559
return res;
479560
}
480561

562+
template<typename Numeric>
563+
bool named_semilogx(const std::string& name, const std::vector<Numeric>& x, const std::vector<Numeric>& y, const std::string& format = "")
564+
{
565+
PyObject* kwargs = PyDict_New();
566+
PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str()));
567+
568+
PyObject* xarray = get_array(x);
569+
PyObject* yarray = get_array(y);
570+
571+
PyObject* pystring = PyString_FromString(format.c_str());
572+
573+
PyObject* plot_args = PyTuple_New(3);
574+
PyTuple_SetItem(plot_args, 0, xarray);
575+
PyTuple_SetItem(plot_args, 1, yarray);
576+
PyTuple_SetItem(plot_args, 2, pystring);
577+
578+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_semilogx, plot_args, kwargs);
579+
580+
Py_DECREF(kwargs);
581+
Py_DECREF(plot_args);
582+
if(res) Py_DECREF(res);
583+
584+
return res;
585+
}
586+
587+
template<typename Numeric>
588+
bool named_semilogy(const std::string& name, const std::vector<Numeric>& x, const std::vector<Numeric>& y, const std::string& format = "")
589+
{
590+
PyObject* kwargs = PyDict_New();
591+
PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str()));
592+
593+
PyObject* xarray = get_array(x);
594+
PyObject* yarray = get_array(y);
595+
596+
PyObject* pystring = PyString_FromString(format.c_str());
597+
598+
PyObject* plot_args = PyTuple_New(3);
599+
PyTuple_SetItem(plot_args, 0, xarray);
600+
PyTuple_SetItem(plot_args, 1, yarray);
601+
PyTuple_SetItem(plot_args, 2, pystring);
602+
603+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_semilogy, plot_args, kwargs);
604+
605+
Py_DECREF(kwargs);
606+
Py_DECREF(plot_args);
607+
if(res) Py_DECREF(res);
608+
609+
return res;
610+
}
611+
612+
template<typename Numeric>
613+
bool named_loglog(const std::string& name, const std::vector<Numeric>& x, const std::vector<Numeric>& y, const std::string& format = "")
614+
{
615+
PyObject* kwargs = PyDict_New();
616+
PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str()));
617+
618+
PyObject* xarray = get_array(x);
619+
PyObject* yarray = get_array(y);
620+
621+
PyObject* pystring = PyString_FromString(format.c_str());
622+
623+
PyObject* plot_args = PyTuple_New(3);
624+
PyTuple_SetItem(plot_args, 0, xarray);
625+
PyTuple_SetItem(plot_args, 1, yarray);
626+
PyTuple_SetItem(plot_args, 2, pystring);
627+
628+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_loglog, plot_args, kwargs);
629+
630+
Py_DECREF(kwargs);
631+
Py_DECREF(plot_args);
632+
if(res) Py_DECREF(res);
633+
634+
return res;
635+
}
636+
481637
template<typename Numeric>
482638
bool plot(const std::vector<Numeric>& y, const std::string& format = "")
483639
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy