How to use the netgraph._main.InteractiveGraph function in netgraph

To help you get started, we’ve selected a few netgraph 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 paulbrodersen / netgraph / netgraph / _main.py View on Github external
return InteractiveClass(graph, node_labels=node_labels, edge_labels=edge_labels, **kwargs)


if __name__ == "__main__":

    # create a figure for each possible combination of inputs
    # TODO:
    # - test node properties such as node_color, node_size, node_shape, etc.

    arguments = OrderedDict(directed=(True, False),
                            strictly_positive=(True, False),
                            weighted=(True, False),
                            show_node_labels=(True,False),
                            show_edge_labels=(True, False),
                            test_format=('sparse', 'dense', 'networkx', 'igraph'),
                            InteractiveGraph=(None, InteractiveGraph))

    combinations = itertools.product(*arguments.values())

    for ii, combination in enumerate(combinations):
        print(ii, zip(arguments.keys(), combination))
        fig, ax = plt.subplots(1, 1, figsize=(16,16))
        kwargs = dict(zip(arguments.keys(), combination))
        graph = test(ax=ax, **kwargs)
        title = ''.join(['{}: {}, '.format(key, value) for (key, value) in kwargs.items()])
        filename = ''.join(['{}-{}_'.format(key, value) for (key, value) in kwargs.items()])
        filename = filename[:-1] # remove trailing underscore
        ax.set_title(title)
        fig.savefig('../figures/{}.pdf'.format(filename))
        plt.close()
github paulbrodersen / netgraph / netgraph / _interactive_variants.py View on Github external
import numpy as np
import matplotlib.pyplot as plt
import itertools

from functools import partial
from matplotlib.patches import Rectangle

try:
    from ._main import InteractiveGraph, BASE_EDGE_WIDTH, BASE_NODE_SIZE, test
    from ._line_supercover import line_supercover
except ValueError:
    from _main import InteractiveGraph, BASE_EDGE_WIDTH, BASE_NODE_SIZE, test
    from _line_supercover import line_supercover


class InteractiveGrid(InteractiveGraph):
    """
    As InteractiveGraph, but node positions are fixed to a grid with unit spacing.

    Pressing 'g' will show the grid lines.
    Pressing 't' will show all tiles occupied by a node or crossed over by an egde.

    NOTE:
    -----
    For this class, the default netgraph node size and edge width are probably far too small for a medium sized graph.
    In my experience, for a graph with 20-50 nodes, a node size of 45 and an edge width of 15 tend to work well.
    Change your code accordingly. For example:

    g = InteractiveGrid(graph, node_size=45, edge_width=15)

    """
github paulbrodersen / netgraph / netgraph / _interactive_variants.py View on Github external
n = 4
    adj = np.ones((n,n))
    adj = np.triu(adj, 1)
    pos = np.random.rand(n,2)
    pos[:,0] *= 10
    pos[:,1] *= 5
    pos = {ii:xy for ii, xy in enumerate(pos)}

    fig, ax = plt.subplots()
    ax.set(xlim=[0, 10], ylim=[0, 5])
    g = InteractiveGrid(adj, pos, ax=ax, node_size=15.)

    return g


class InteractiveHypergraph(InteractiveGraph):
    """
    As InteractiveGraph, but nodes can be combined into a hypernode.

    Pressing 'c' will fuse selected node artists into a single node.
    """

    def __init__(self, *args, **kwargs):

        super(InteractiveHypergraph, self).__init__(*args, **kwargs)

        # bookkeeping
        self.hypernode_to_nodes = dict()

        # for redrawing after fusion
        self.kwargs = kwargs
github paulbrodersen / netgraph / netgraph / _interactive_variants.py View on Github external
# del self.edge_weight[edge]            # TODO: get / set property for hyperedges; otherwise these raises KeyError
        # del self.edge_color[edge]             # TODO: get / set property for hyperedges; otherwise these raises KeyError
        # del self.edge_zorder[edge]            # TODO: get / set property for hyperedges; otherwise these raises KeyError

        source, target = edge
        if source != target: # i.e. skip self-loops as they have no corresponding artist
            self.edge_artists[edge].remove()
            del self.edge_artists[edge]

            # if hasattr(self, 'edge_labels'):
            #     del self.edge_labels[edge]        # TODO: get / set property for hyperedges; otherwise these raises KeyError
            #     edge_label_artists[edge].remove() # TODO: get / set property for hyperedges; otherwise these raises KeyError
            #     del self.edge_label_artists[edge] # TODO: get / set property for hyperedges; otherwise these raises KeyError


class InteractivelyConstructDestroyGraph(InteractiveGraph):
    """
    Interactively add and remove nodes and edges.

    Pressing 'A' will add a node to the graph.
    Pressing 'D' will remove a selected node.
    Pressing 'a' will add edges between all selected nodes.
    Pressing 'd' will remove edges between all selected nodes.
    Pressing 'r' will reverse the direction of edges between all selected nodes.

    See also:
    ---------
    InteractiveGraph, Graph, draw

    """

    def __init__(self, *args, **kwargs):