How to use the kmapper.visuals._color_function function in kmapper

To help you get started, we’ve selected a few kmapper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-tda / kepler-mapper / test / test_visuals.py View on Github external
def test_color_hist_matches_nodes(self):
        """ The histogram colors dont seem to match the node colors, this should confirm the colors will match and we need to look at the javascript instead.
        """

        color_function = np.array([0.55] * 10 + [0.0] * 10)
        member_ids = [1, 2, 3, 4, 5, 6]
        hist = build_histogram(color_function[member_ids])
        c = round(_color_function(member_ids, color_function), 2)
        single_bar = [bar for bar in hist if bar["perc"] == 100.0]

        assert len(single_bar) == 1
        assert _map_val2color(c, 0.0, 1.0) == single_bar[0]["color"]
github scikit-tda / kepler-mapper / kmapper / plotlyviz.py View on Github external
custom_tooltips,
    colorscale,
):

    json_dict = {"nodes": [], "links": []}
    node_id_to_num = {}
    for i, (node_id, member_ids) in enumerate(simplicial_complex["nodes"].items()):
        node_id_to_num[node_id] = i
        projection_stats, cluster_stats, member_histogram = _tooltip_components(
            member_ids, X, X_names, lens, lens_names, color_function, i, colorscale
        )
        n = {
            "id": i,
            "name": node_id,
            "member_ids": member_ids,
            "color": _color_function(member_ids, color_function),
            "size": _size_node(member_ids),
            "cluster": cluster_stats,
            "distribution": member_histogram,
            "projection": projection_stats,
            "custom_tooltips": custom_tooltips,
        }

        json_dict["nodes"].append(n)
    for i, (node_id, linked_node_ids) in enumerate(simplicial_complex["links"].items()):
        for linked_node_id in linked_node_ids:
            lnk = {
                "source": node_id_to_num[node_id],
                "target": node_id_to_num[linked_node_id],
            }

            json_dict["links"].append(lnk)