8000 added support for scatter plots · michLab/matplotlib-cpp@78719eb · GitHub
[go: up one dir, main page]

Skip to content

Commit 78719eb

Browse files
mdmosley1lava
authored andcommitted
added support for scatter plots
1 parent 073dd98 commit 78719eb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

matplotlibcpp.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct _interpreter {
4444
PyObject *s_python_function_loglog;
4545
PyObject *s_python_function_fill_between;
4646
PyObject *s_python_function_hist;
47+
PyObject *s_python_function_scatter;
4748
PyObject *s_python_function_subplot;
4849
PyObject *s_python_function_legend;
4950
PyObject *s_python_function_xlim;
@@ -151,6 +152,7 @@ struct _interpreter {
151152
s_python_function_loglog = PyObject_GetAttrString(pymod, "loglog");
152153
s_python_function_fill_between = PyObject_GetAttrString(pymod, "fill_between");
153154
s_python_function_hist = PyObject_GetAttrString(pymod,"hist");
155+
s_python_function_scatter = PyObject_GetAttrString(pymod,"scatter");
154156
s_python_function_subplot = PyObject_GetAttrString(pymod, "subplot");
155157
s_python_function_legend = PyObject_GetAttrString(pymod, "legend");
156158
s_python_function_ylim = PyObject_GetAttrString(pymod, "ylim");
@@ -454,6 +456,31 @@ bool hist(const std::vector<Numeric>& y, long bins=10,std::string color="b", dou
454456
return res;
455457
}
456458

459+
template<typename NumericX, typename NumericY>
460+
bool scatter(const std::vector<NumericX>& x,
461+
const std::vector<NumericY>& y,
462+
const double s=1.0) // The marker size in points**2
463+
{
464+
assert(x.size() == y.size());
465+
466+
PyObject* xarray = get_array(x);
467+
PyObject* yarray = get_array(y);
468+
469+
PyObject* kwargs = PyDict_New();
470+
PyDict_SetItemString(kwargs, "s", PyLong_FromLong(s));
471+
472+
PyObject* plot_args = PyTuple_New(2);
473+
PyTuple_SetItem(plot_args, 0, xarray);
474+
PyTuple_SetItem(plot_args, 1, yarray);
475+
476+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_scatter, plot_args, kwargs);
477+
478+
Py_DECREF(plot_args);
479+
if(res) Py_DECREF(res);
480+
481+
return res;
482+
}
483+
457484
template< typename Numeric>
458485
bool named_hist(std::string label,const std::vector<Numeric>& y, long bins=10, std::string color="b", double alpha=1.0)
459486
{

0 commit comments

Comments
 (0)
0