Skip to content

Colormap to scatter_colored #365

Description

@Nicoskin

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;
    }
    

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions