Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Colormap to scatter_colored #365

Open
Nicoskin opened this issue Nov 10, 2024 · 0 comments
Open

Colormap to scatter_colored #365

Nicoskin opened this issue Nov 10, 2024 · 0 comments

Comments

@Nicoskin
Copy link

I've added a new version of the scatter_colored function to manage the colormap. It would be great if I could push this!

template<typename NumericX, typename NumericY, typename NumericColors>
    bool scatter_colored(const std::vector<NumericX>& x,
                 const std::vector<NumericY>& y,
                 const std::vector<NumericColors>& colors,
                 const double s=1.0, // The marker size in points**2
                 const std::string& cmap="hsv",
                 const std::map<std::string, std::string> & keywords = {})
    {
        detail::_interpreter::get();

        assert(x.size() == y.size());

        PyObject* xarray = detail::get_array(x);
        PyObject* yarray = detail::get_array(y);
        PyObject* colors_array = detail::get_array(colors);
        PyObject* cm = PyString_FromString(cmap.c_str());

        PyObject* kwargs = PyDict_New();
        PyDict_SetItemString(kwargs, "s", PyLong_FromLong(s));
        PyDict_SetItemString(kwargs, "c", colors_array);
        PyDict_SetItemString(kwargs, "cmap", cm);

        for (const auto& it : keywords)
        {
            PyDict_SetItemString(kwargs, it.first.c_str(), PyString_FromString(it.second.c_str()));
        }

        PyObject* plot_args = PyTuple_New(2);
        PyTuple_SetItem(plot_args, 0, xarray);
        PyTuple_SetItem(plot_args, 1, yarray);

        PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_scatter, plot_args, kwargs);

        Py_DECREF(plot_args);
        Py_DECREF(kwargs);
        if(res) Py_DECREF(res);

        return res;
    }
    
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant