How to use nxviz - 10 common examples

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_nxviz.py View on Github external
def test_init_sort_and_group_nodes():
    """
    Tests initialization with sorting and grouping of nodes.

    This tests that the nodes are ordered correctly when first grouped on the
    `node_grouping` key, and then sorted within each group on the `node_order`
    key.
    """
    G = make_graph_for_grouping()  # noqa

    b = BasePlot(graph=G, node_grouping="affiliation", node_order="year")

    assert b.nodes == [
        n
        for n, d in sorted(
            G.nodes(data=True),
            key=lambda x: (x[1]["affiliation"], x[1]["year"]),
        )
github ericmjl / nxviz / tests / test_nxviz.py View on Github external
def test_init_node_colors():
    """
    Check node color initialization.

    Does two checks:
    1. If node_color is not passed in as a keyword argument, check that
       self.node_colors is a list of 'blue', of length (number of nodes).
    2. If node_color is passed in as a keyword argument, check that
       self.node_colors is a list with more than one element.
    """
    G = make_graph_for_grouping()  # noqa
    b = BasePlot(graph=G, node_color="year")
    assert len(set(b.node_colors)) > 1

    G = make_graph_for_grouping()  # noqa
    b = BasePlot(graph=G)
    assert len(set(b.node_colors)) == 1
github ericmjl / nxviz / tests / test_nxviz.py View on Github external
def test_init_group_nodes():
    """
    Tests initialization with grouping of nodes.

    This only tests that the nodes are ordered correctly when sorted on the
    `node_grouping` key.
    """
    G = make_graph_for_grouping()  # noqa
    b = BasePlot(graph=G, node_grouping="affiliation")

    assert b.nodes == [
        n
        for n, d in sorted(
            G.nodes(data=True), key=lambda x: x[1]["affiliation"]
        )
github ericmjl / nxviz / tests / test_nxviz.py View on Github external
def test_init_sort_nodes():
    """
    Tests initialization with sorting of nodes.

    This tests that the nodes are ordered correctly when sorted on the
    "node_order" key.
    """
    G = make_graph_for_grouping()  # noqa

    b = BasePlot(graph=G, node_order="year")

    assert b.nodes == [
        n for n, d in sorted(G.nodes(data=True), key=lambda x: x[1]["year"])
    ]
github ericmjl / nxviz / tests / test_nxviz.py View on Github external
def test_init_edge_colors():
    """
    Check edge color initialization.

    Does two checks:
    1.  If edge_color is passed in as a keyword argument, check that
        self.edge_colors is a list with more than one element.
    2.  If edge_color is not passed in as a keyword argument, check that
        self.edge_colors is a list of 'black', of length 0.
    """
    G = make_graph_for_edges()  # noqa
    b = BasePlot(graph=G, edge_color="weight")
    assert len(set(b.edge_colors)) > 1

    G = make_graph_for_grouping()  # noqa
    b = BasePlot(graph=G)
    assert len(set(b.edge_colors)) == 0
github ericmjl / nxviz / tests / test_geometry.py View on Github external
def test_get_cartesian(r, theta):
    """
    In this test, we are testing to make sure that `get_cartesian` remains a
    wrapper around polcart's `to_cartesian`.
    """
    assume(np.isfinite(theta))
    assume(np.isfinite(r))
    assert get_cartesian(r, theta) == polcart.to_cartesian(r, theta)
github ericmjl / nxviz / tests / test_plots.py View on Github external
def test_edge_color():
    # add color as attribute and fill with random numbers
    edges = G.edges()
    for u, v in edges:
        G[u][v]["type"] = "a" if random() < 0.5 else "b"
    # also extract list for testing
    types = [G[u][v]["type"] for u, v in edges]
    # add color as property
    c = CircosPlot(G, edge_color="type")
    assert corresponding_lists(c.edge_colors, types)
    a = ArcPlot(G, edge_color="type")
    assert corresponding_lists(a.edge_colors, types)
github ericmjl / nxviz / tests / test_plots.py View on Github external
def test_circos_plot():
    c = CircosPlot(G)  # noqa: F841
    diff = diff_plots(c, "circos.png", baseline_dir, result_dir)
    assert diff is None
github ericmjl / nxviz / tests / test_plots.py View on Github external
def test_plot_size():
    c = CircosPlot(G, figsize=(3, 3))  # noqa: F841
    diff = diff_plots(c, "circos33.png", baseline_dir, result_dir)
    assert diff is None
github ericmjl / nxviz / tests / test_plots.py View on Github external
def test_edge_widths():
    # add weight as attribute and fill with random numbers
    edges = G.edges()
    for u, v in edges:
        G[u][v]["weight"] = random()
    # also extract list for testing
    weights = [G[u][v]["weight"] for u, v in edges]
    # add weights as property
    c = CircosPlot(G, edge_width="weight")
    assert c.edge_widths == weights
    a = ArcPlot(G, edge_width="weight")
    assert a.edge_widths == weights
    # add weights as list
    c = CircosPlot(G, edge_width=weights)
    assert c.edge_widths == weights
    a = ArcPlot(G, edge_width=weights)
    assert a.edge_widths == weights