def compute_edge_colors(G):
    """ 
    Compute the edge colors. 
    NOTE: This function is copied from the nxviz package! 
    """
    data = [G.graph.edges[n][G.edge_color] for n in G.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
        G.edge_colors.append(cmap(idx))
    # Add colorbar if required.
    if len(data_reduced) > 1 and dtype == "continuous":
        G.sm = plt.cm.ScalarMappable(
            cmap=cmap,
            norm=plt.Normalize(
                vmin=min(data_reduced),
                vmax=max(data_reduced),
            ),
        )
        G.sm._A = []
    return cmap
Beispiel #2
0
def test_binomial():
    assert infer_data_type(binomial) == "categorical"
    assert infer_data_type(binomial_float) == "categorical"
    assert infer_data_type(binomial_integer) == "categorical"
Beispiel #3
0
def test_infer_data_type():
    assert infer_data_type(categorical) == "categorical"
    assert infer_data_type(ordinal) == "ordinal"
    assert infer_data_type(continuous) == "continuous"
Beispiel #4
0
def test_unknown_data_type():
    with pytest.raises(ValueError):
        infer_data_type(unknown_type)
Beispiel #5
0
def test_infer_data_type():
    assert infer_data_type(categorical) == 'categorical'
    assert infer_data_type(ordinal) == 'ordinal'
    assert infer_data_type(continuous) == 'continuous'