Beispiel #1
0
def plot_node(node, ax=None, linewidth=2):
    if ax is None:
        ax = plt.gca()
    connectivity = make_network([0, 0, 0], n_node=3)
    connectivity[2, 1] = node[1]
    init_pos = np.array([[0, .5, 1.], [0., 0., 0.]])
    options = dict(iterations=0,
                   edge_curve=True,
                   directional=True,
                   node_color='k',
                   node_alpha=1.,
                   negative_weights=True,
                   init_pos=init_pos,
                   ax=ax,
                   final_pos=None,
                   node_size=linewidth * 100,
                   edge_width=linewidth,
                   self_edge=1000,
                   clim=[-1, 1],
                   arrowstyle='->')
    G, nodes, = plot_graph(connectivity, edge_color='k', **options)
    nodes.set_linewidths(linewidth)
    nodes.set_zorder(-1)
    connectivity = make_network(node, n_node=3)
    connectivity[0, 1] = 0
    G, nodes, = plot_graph(connectivity,
                           edge_color=plt.get_cmap('bwr'),
                           **options)
    nodes.set_linewidths(linewidth)
    nodes.set_zorder(-1)
    ax.scatter(.5, 0, linewidth * 100, color='w', zorder=3)
    ax.set_aspect('equal')
    ax.patch.set_visible(False)
    ax.set_ylim([-.2, .2])
    ax.set_xlim([-.1, 1.1])
Beispiel #2
0
def plot_node(node, ax=None, linewidth=2):
    if ax is None:
        ax = plt.gca()
    connectivity = make_network([0, 0, 0], n_node=3)
    connectivity[2, 1] = node[1]
    init_pos = np.array([[0, .5, 1.], [0., 0., 0.]])
    options = dict(
        iterations=0, edge_curve=True, directional=True,
        node_color='k', node_alpha=1., negative_weights=True,
        init_pos=init_pos, ax=ax, final_pos=None, node_size=linewidth*100,
        edge_width=linewidth, self_edge=1000, clim=[-1, 1], arrowstyle='->')
    G, nodes, = plot_graph(connectivity,  edge_color='k', **options)
    nodes.set_linewidths(linewidth)
    nodes.set_zorder(-1)
    connectivity = make_network(node, n_node=3)
    connectivity[0, 1] = 0
    G, nodes, = plot_graph(connectivity,  edge_color=plt.get_cmap('bwr'),
                           **options)
    nodes.set_linewidths(linewidth)
    nodes.set_zorder(-1)
    ax.scatter(.5, 0, linewidth*100, color='w', zorder=3)
    ax.set_aspect('equal')
    ax.patch.set_visible(False)
    ax.set_ylim([-.2, .2])
    ax.set_xlim([-.1, 1.1])
Beispiel #3
0
def plot_network(network, n_columns=1, n_regions=1, radius=None, ax=None,
                 linewidth=2, cmap=None, clim=None):
    """This plot the columnar network"""
    from matplotlib.patches import ArrowStyle
    ax = plt.subplot() if ax is None else ax
    cmap = plt.get_cmap('bwr') if cmap is None else cmap
    clim = [-1, 1] if clim is None else clim
    # network is made of n_columns + entry node
    n_nodes = (len(network) // n_columns - 1) // n_regions
    init_pos = np.zeros((network.shape[0], 2))
    x = np.linspace(-1, 1, n_regions)
    y = np.linspace(-1, 1, n_columns)
    if radius is None:
        radius = 1. / n_columns
    z = np.linspace(-np.pi / 2, 3 * np.pi / 2, n_nodes + 1)[:-1]
    z = np.transpose([np.cos(z), np.sin(z) + 1.])
    for column, region, node in itertools.product(
            range(n_columns), range(n_regions), range(-1, n_nodes)):
        sel = select_nodes(n_columns, n_regions, n_nodes=n_nodes,
                           column=column, region=region, node=node)
        if node == -1:
            first_node = np.diff(x[:2]) if len(x) > 1 else 1.
            init_pos[sel, 0] = -1 - first_node
            init_pos[sel, 1] = y[column] - 1 * radius
        else:
            init_pos[sel, 0] = x[region] + z[node, 0] * radius
        init_pos[sel, 1] = y[column] + z[node, 1] * radius
    arrow_style = ArrowStyle.Fancy(head_length=1., head_width=1.25,
                                   tail_width=.25)
    G, nodes, = plot_graph(
        network, iterations=0, edge_curve=True, directional=True,
        node_color='w', node_alpha=1., edge_color=cmap,
        negative_weights=True, init_pos=init_pos.T, ax=ax, final_pos=None,
        node_size=linewidth*100, edge_width=linewidth, self_edge=1000,
        clim=clim, arrowstyle=arrow_style)
    nodes.set_linewidths(linewidth)
    ax.set_aspect('equal')
    ax.patch.set_visible(False)
    if n_columns > 1:
        ax.set_ylim([-.2, 1.2])
    if n_regions > 1:
        ax.set_xlim([-.2, 1.2])
Beispiel #4
0
def plot_network(network,
                 n_columns=1,
                 n_regions=1,
                 radius=None,
                 ax=None,
                 linewidth=2,
                 cmap=None,
                 clim=None):
    """This plot the columnar network"""
    from matplotlib.patches import ArrowStyle
    ax = plt.subplot() if ax is None else ax
    cmap = plt.get_cmap('bwr') if cmap is None else cmap
    clim = [-1, 1] if clim is None else clim
    # network is made of n_columns + entry node
    n_nodes = (len(network) // n_columns - 1) // n_regions
    init_pos = np.zeros((network.shape[0], 2))
    x = np.linspace(-1, 1, n_regions)
    y = np.linspace(-1, 1, n_columns)
    if radius is None:
        radius = 1. / n_columns
    z = np.linspace(-np.pi / 2, 3 * np.pi / 2, n_nodes + 1)[:-1]
    z = np.transpose([np.cos(z), np.sin(z) + 1.])
    for column, region, node in itertools.product(range(n_columns),
                                                  range(n_regions),
                                                  range(-1, n_nodes)):
        sel = select_nodes(n_columns,
                           n_regions,
                           n_nodes=n_nodes,
                           column=column,
                           region=region,
                           node=node)
        if node == -1:
            first_node = np.diff(x[:2]) if len(x) > 1 else 1.
            init_pos[sel, 0] = -1 - first_node
            init_pos[sel, 1] = y[column] - 1 * radius
        else:
            init_pos[sel, 0] = x[region] + z[node, 0] * radius
        init_pos[sel, 1] = y[column] + z[node, 1] * radius
    arrow_style = ArrowStyle.Fancy(head_length=1.,
                                   head_width=1.25,
                                   tail_width=.25)
    G, nodes, = plot_graph(network,
                           iterations=0,
                           edge_curve=True,
                           directional=True,
                           node_color='w',
                           node_alpha=1.,
                           edge_color=cmap,
                           negative_weights=True,
                           init_pos=init_pos.T,
                           ax=ax,
                           final_pos=None,
                           node_size=linewidth * 100,
                           edge_width=linewidth,
                           self_edge=1000,
                           clim=clim,
                           arrowstyle=arrow_style)
    nodes.set_linewidths(linewidth)
    ax.set_aspect('equal')
    ax.patch.set_visible(False)
    if n_columns > 1:
        ax.set_ylim([-.2, 1.2])
    if n_regions > 1:
        ax.set_xlim([-.2, 1.2])