How to use the nxviz.utils.infer_data_type function in nxviz

To help you get started, we’ve selected a few nxviz 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 ericmjl / nxviz / tests / test_utils.py View on Github external
def test_infer_data_type():
    assert infer_data_type(categorical) == "categorical"
    assert infer_data_type(ordinal) == "ordinal"
    assert infer_data_type(continuous) == "continuous"
github ericmjl / nxviz / tests / test_utils.py View on Github external
def test_binomial():
    assert infer_data_type(binomial) == "categorical"
    assert infer_data_type(binomial_float) == "categorical"
    assert infer_data_type(binomial_integer) == "categorical"
github ericmjl / nxviz / tests / test_utils.py View on Github external
def test_infer_data_type():
    assert infer_data_type(categorical) == "categorical"
    assert infer_data_type(ordinal) == "ordinal"
    assert infer_data_type(continuous) == "continuous"
github ericmjl / nxviz / tests / test_utils.py View on Github external
def test_binomial():
    assert infer_data_type(binomial) == "categorical"
    assert infer_data_type(binomial_float) == "categorical"
    assert infer_data_type(binomial_integer) == "categorical"
github ericmjl / nxviz / tests / test_utils.py View on Github external
def test_infer_data_type():
    assert infer_data_type(categorical) == "categorical"
    assert infer_data_type(ordinal) == "ordinal"
    assert infer_data_type(continuous) == "continuous"
github ericmjl / nxviz / tests / test_utils.py View on Github external
def test_unknown_data_type():
    with pytest.raises(ValueError):
        infer_data_type(unknown_type)
github ericmjl / nxviz / tests / test_utils.py View on Github external
def test_binomial():
    assert infer_data_type(binomial) == "categorical"
    assert infer_data_type(binomial_float) == "categorical"
    assert infer_data_type(binomial_integer) == "categorical"
github ericmjl / nxviz / nxviz / plots.py View on Github external
def compute_edge_colors(self):
        """Compute the edge colors."""
        data = [self.graph.edges[n][self.edge_color] for n in self.edges]
        data_reduced = sorted(list(set(data)))

        dtype = infer_data_type(data)
        n_grps = num_discrete_groups(data)
        if dtype == "categorical" or dtype == "ordinal":
            if n_grps <= 8:
                cmap = get_cmap(
                    cmaps["Accent_{0}".format(n_grps)].mpl_colormap
                )
            else:
                cmap = n_group_colorpallet(n_grps)
        elif dtype == "continuous" and not is_data_diverging(data):
            cmap = get_cmap(cmaps["weights"])

        for d in data:
            idx = data_reduced.index(d) / n_grps
            self.edge_colors.append(cmap(idx))
        # Add colorbar if required.
        logging.debug("length of data_reduced: {0}".format(len(data_reduced)))
github ericmjl / nxviz / nxviz / plots.py View on Github external
def compute_node_colors(self):
        """Compute the node colors. Also computes the colorbar."""
        data = [self.graph.nodes[n][self.node_color] for n in self.nodes]

        if self.group_order == "alphabetically":
            data_reduced = sorted(list(set(data)))
        elif self.group_order == "default":
            data_reduced = list(unique_everseen(data))

        dtype = infer_data_type(data)
        n_grps = num_discrete_groups(data)

        if dtype == "categorical" or dtype == "ordinal":
            if n_grps <= 8:
                cmap = get_cmap(
                    cmaps["Accent_{0}".format(n_grps)].mpl_colormap
                )
            else:
                cmap = n_group_colorpallet(n_grps)
        elif dtype == "continuous" and not is_data_diverging(data):
            cmap = get_cmap(cmaps["continuous"].mpl_colormap)
        elif dtype == "continuous" and is_data_diverging(data):
            cmap = get_cmap(cmaps["diverging"].mpl_colormap)

        for d in data:
            idx = data_reduced.index(d) / n_grps