Skip to content

Commit 6150108

Browse files
kesha787898Benno Evers
authored andcommitted
added scatter with colors
1 parent 1480780 commit 6150108

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

matplotlibcpp.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,44 @@ bool scatter(const std::vector<NumericX>& x,
10221022
return res;
10231023
}
10241024

1025+
template<typename NumericX, typename NumericY, typename NumericColors>
1026+
bool scatter_colored(const std::vector<NumericX>& x,
1027+
const std::vector<NumericY>& y,
1028+
const std::vector<NumericColors>& colors,
1029+
const double s=1.0, // The marker size in points**2
1030+
const std::map<std::string, std::string> & keywords = {})
1031+
{
1032+
detail::_interpreter::get();
1033+
1034+
assert(x.size() == y.size());
1035+
1036+
PyObject* xarray = detail::get_array(x);
1037+
PyObject* yarray = detail::get_array(y);
1038+
PyObject* colors_array = detail::get_array(colors);
1039+
1040+
PyObject* kwargs = PyDict_New();
1041+
PyDict_SetItemString(kwargs, "s", PyLong_FromLong(s));
1042+
PyDict_SetItemString(kwargs, "c", colors_array);
1043+
1044+
for (const auto& it : keywords)
1045+
{
1046+
PyDict_SetItemString(kwargs, it.first.c_str(), PyString_FromString(it.second.c_str()));
1047+
}
1048+
1049+
PyObject* plot_args = PyTuple_New(2);
1050+
PyTuple_SetItem(plot_args, 0, xarray);
1051+
PyTuple_SetItem(plot_args, 1, yarray);
1052+
1053+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_scatter, plot_args, kwargs);
1054+
1055+
Py_DECREF(plot_args);
1056+
Py_DECREF(kwargs);
1057+
if(res) Py_DECREF(res);
1058+
1059+
return res;
1060+
}
1061+
1062+
10251063
template<typename NumericX, typename NumericY, typename NumericZ>
10261064
bool scatter(const std::vector<NumericX>& x,
10271065
const std::vector<NumericY>& y,

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