コード例 #1
0
def test_networkx_layout_with_graph():
    """
    Testing the various inputs to the networkx layout
    """

    settings = dict(name="networkx_layout")
    if nx:
        # empty input
        # testing.assert_raises(ValueError("Requires networkx input"), get_layout(**settings))

        # define graph
        graph = nx.complete_graph(5)
        # define positions
        layout = np.random.rand(5, 2)
        settings['graph'] = graph
        settings['layout'] = layout

        # test numpy array input
        testing.assert_true(
            isinstance(get_layout(**settings), NetworkxCoordinates))
        # testing string input
        settings['layout'] = 'circular'
        testing.assert_true(
            isinstance(get_layout(**settings), NetworkxCoordinates))
        # testing dict input
        settings['layout'] = nx.circular_layout(graph)
        testing.assert_true(
            isinstance(get_layout(**settings), NetworkxCoordinates))
コード例 #2
0
ファイル: test_layouts.py プロジェクト: Eric89GXL/vispy
def test_get_layout():
    from vispy.visuals.graphs.layouts.random import random

    # Simple retrieval
    assert_equal(random, get_layout('random'))

    # Pass arguments
    fruchterman_reingold = get_layout('force_directed', iterations=100)
    assert_equal(fruchterman_reingold.iterations, 100)

    # Check if layout exists
    assert_raises(KeyError, get_layout, 'fdgdfgs_non_existent')
コード例 #3
0
ファイル: test_layouts.py プロジェクト: yasiral/vispy
def test_get_layout():
    from vispy.visuals.graphs.layouts.random import random

    # Simple retrieval
    assert_equal(random, get_layout('random'))

    # Pass arguments
    fruchterman_reingold = get_layout('force_directed', iterations=100)
    assert_equal(fruchterman_reingold.iterations, 100)

    # Check if layout exists
    assert_raises(KeyError, get_layout, 'fdgdfgs_non_existent')
コード例 #4
0
ファイル: test_layouts.py プロジェクト: Eric89GXL/vispy
def test_random_layout():
    layout = get_layout('random')

    expected_pos = np.array([
        [0.22270932715095826, 0.7728936927702302],
        [0.6298054094517744, 0.21851589821484974],
        [0.75002099889163, 0.5592076821676369],
        [0.1786754307911973, 0.6442165368790972],
        [0.5979199081208609, 0.615159318836822],
        [0.46328431255222746, 0.3582897386994869],
        [0.9595461883180398, 0.2350580044144016],
        [0.094482942129406, 0.20584398882694932],
        [0.5758593091748346, 0.8158957494444451],
        [0.5908647616961652, 0.1584550825482285]
    ])

    expected_vertices = np.array([
        [0.22270932715095826, 0.7728936927702302],
        [0.6298054094517744, 0.21851589821484974],
        [0.6298054094517744, 0.21851589821484974],
        [0.22270932715095826, 0.7728936927702302],
        [0.6298054094517744, 0.21851589821484974],
        [0.5979199081208609, 0.615159318836822],
        [0.6298054094517744, 0.21851589821484974],
        [0.9595461883180398, 0.2350580044144016],
        [0.6298054094517744, 0.21851589821484974],
        [0.094482942129406, 0.20584398882694932],
        [0.1786754307911973, 0.6442165368790972],
        [0.5758593091748346, 0.8158957494444451],
        [0.5979199081208609, 0.615159318836822],
        [0.6298054094517744, 0.21851589821484974],
        [0.9595461883180398, 0.2350580044144016],
        [0.6298054094517744, 0.21851589821484974],
        [0.094482942129406, 0.20584398882694932],
        [0.6298054094517744, 0.21851589821484974],
        [0.5758593091748346, 0.8158957494444451],
        [0.1786754307911973, 0.6442165368790972],
        [0.5758593091748346, 0.8158957494444451],
        [0.5908647616961652, 0.1584550825482285],
        [0.5908647616961652, 0.1584550825482285],
        [0.5758593091748346, 0.8158957494444451]
    ])

    pos, line_vertices, arrows = next(layout(adjacency_mat,
                                             random_state=0xDEADBEEF))

    assert_allclose(pos, expected_pos, atol=1e-7)
    assert_allclose(line_vertices, expected_vertices, atol=1e-7)
コード例 #5
0
ファイル: graph.py プロジェクト: Eric89GXL/vispy
    def __init__(self):
        app.Canvas.__init__(self, title="Simple NetworkX Graph",
                            keys="interactive", size=(600, 600))

        graph = nx.adjacency_matrix(
            nx.fast_gnp_random_graph(500, 0.005, directed=True))
        layout = layouts.get_layout('force_directed', iterations=100)

        self.visual = visuals.GraphVisual(
            graph, layout=layout, line_color='black', arrow_type="stealth",
            arrow_size=30, node_symbol="disc", node_size=20,
            face_color=(1, 0, 0, 0.5), border_width=0.0, animate=True,
            directed=False)

        self.visual.transform = STTransform(self.visual_size, (20, 20))
        self.show()
コード例 #6
0
ファイル: graph.py プロジェクト: jruel4/AlphaScan
    def __init__(self):
        app.Canvas.__init__(self, title="Simple NetworkX Graph",
                            keys="interactive", size=(600, 600))

        graph = nx.adjacency_matrix(
            nx.fast_gnp_random_graph(500, 0.005, directed=True))
        layout = layouts.get_layout('force_directed', iterations=100)

        self.visual = visuals.GraphVisual(
            graph, layout=layout, line_color='black', arrow_type="stealth",
            arrow_size=30, node_symbol="disc", node_size=20,
            face_color=(1, 0, 0, 0.5), border_width=0.0, animate=True,
            directed=False)

        self.visual.transform = STTransform(self.visual_size, (20, 20))
        self.show()
コード例 #7
0
ファイル: test_layouts.py プロジェクト: Eric89GXL/vispy
def test_circular_layout():
    layout = get_layout('circular')

    expected_pos = np.array([
        [1.0, 0.5],
        [0.9045084714889526, 0.7938926219940186],
        [0.6545084714889526, 0.9755282402038574],
        [0.3454914689064026, 0.9755282402038574],
        [0.09549146890640259, 0.7938926219940186],
        [0.0, 0.4999999701976776],
        [0.09549152851104736, 0.20610731840133667],
        [0.3454914689064026, 0.024471759796142578],
        [0.6545085906982422, 0.024471759796142578],
        [0.9045084714889526, 0.20610734820365906]
    ])

    expected_vertices = np.array([
        [1.0, 0.5],
        [0.9045084714889526, 0.7938926219940186],
        [0.9045084714889526, 0.7938926219940186],
        [1.0, 0.5],
        [0.9045084714889526, 0.7938926219940186],
        [0.09549146890640259, 0.7938926219940186],
        [0.9045084714889526, 0.7938926219940186],
        [0.09549152851104736, 0.20610731840133667],
        [0.9045084714889526, 0.7938926219940186],
        [0.3454914689064026, 0.024471759796142578],
        [0.3454914689064026, 0.9755282402038574],
        [0.6545085906982422, 0.024471759796142578],
        [0.09549146890640259, 0.7938926219940186],
        [0.9045084714889526, 0.7938926219940186],
        [0.09549152851104736, 0.20610731840133667],
        [0.9045084714889526, 0.7938926219940186],
        [0.3454914689064026, 0.024471759796142578],
        [0.9045084714889526, 0.7938926219940186],
        [0.6545085906982422, 0.024471759796142578],
        [0.3454914689064026, 0.9755282402038574],
        [0.6545085906982422, 0.024471759796142578],
        [0.9045084714889526, 0.20610734820365906],
        [0.9045084714889526, 0.20610734820365906],
        [0.6545085906982422, 0.024471759796142578]
    ])

    pos, line_vertices, arrows = next(layout(adjacency_mat))

    assert_allclose(pos, expected_pos, atol=1e-4)
    assert_allclose(line_vertices, expected_vertices, atol=1e-4)
コード例 #8
0
ファイル: test_layouts.py プロジェクト: yasiral/vispy
def test_random_layout():
    layout = get_layout('random')

    expected_pos = np.array([[0.22270932715095826, 0.7728936927702302],
                             [0.6298054094517744, 0.21851589821484974],
                             [0.75002099889163, 0.5592076821676369],
                             [0.1786754307911973, 0.6442165368790972],
                             [0.5979199081208609, 0.615159318836822],
                             [0.46328431255222746, 0.3582897386994869],
                             [0.9595461883180398, 0.2350580044144016],
                             [0.094482942129406, 0.20584398882694932],
                             [0.5758593091748346, 0.8158957494444451],
                             [0.5908647616961652, 0.1584550825482285]])

    expected_vertices = np.array([[0.22270932715095826, 0.7728936927702302],
                                  [0.6298054094517744, 0.21851589821484974],
                                  [0.6298054094517744, 0.21851589821484974],
                                  [0.22270932715095826, 0.7728936927702302],
                                  [0.6298054094517744, 0.21851589821484974],
                                  [0.5979199081208609, 0.615159318836822],
                                  [0.6298054094517744, 0.21851589821484974],
                                  [0.9595461883180398, 0.2350580044144016],
                                  [0.6298054094517744, 0.21851589821484974],
                                  [0.094482942129406, 0.20584398882694932],
                                  [0.1786754307911973, 0.6442165368790972],
                                  [0.5758593091748346, 0.8158957494444451],
                                  [0.5979199081208609, 0.615159318836822],
                                  [0.6298054094517744, 0.21851589821484974],
                                  [0.9595461883180398, 0.2350580044144016],
                                  [0.6298054094517744, 0.21851589821484974],
                                  [0.094482942129406, 0.20584398882694932],
                                  [0.6298054094517744, 0.21851589821484974],
                                  [0.5758593091748346, 0.8158957494444451],
                                  [0.1786754307911973, 0.6442165368790972],
                                  [0.5758593091748346, 0.8158957494444451],
                                  [0.5908647616961652, 0.1584550825482285],
                                  [0.5908647616961652, 0.1584550825482285],
                                  [0.5758593091748346, 0.8158957494444451]])

    pos, line_vertices, arrows = next(
        layout(adjacency_mat, random_state=0xDEADBEEF))

    assert_allclose(pos, expected_pos, atol=1e-7)
    assert_allclose(line_vertices, expected_vertices, atol=1e-7)
コード例 #9
0
ファイル: test_layouts.py プロジェクト: yasiral/vispy
def test_circular_layout():
    layout = get_layout('circular')

    expected_pos = np.array([[1.0, 0.5],
                             [0.9045084714889526, 0.7938926219940186],
                             [0.6545084714889526, 0.9755282402038574],
                             [0.3454914689064026, 0.9755282402038574],
                             [0.09549146890640259, 0.7938926219940186],
                             [0.0, 0.4999999701976776],
                             [0.09549152851104736, 0.20610731840133667],
                             [0.3454914689064026, 0.024471759796142578],
                             [0.6545085906982422, 0.024471759796142578],
                             [0.9045084714889526, 0.20610734820365906]])

    expected_vertices = np.array([[1.0, 0.5],
                                  [0.9045084714889526, 0.7938926219940186],
                                  [0.9045084714889526, 0.7938926219940186],
                                  [1.0, 0.5],
                                  [0.9045084714889526, 0.7938926219940186],
                                  [0.09549146890640259, 0.7938926219940186],
                                  [0.9045084714889526, 0.7938926219940186],
                                  [0.09549152851104736, 0.20610731840133667],
                                  [0.9045084714889526, 0.7938926219940186],
                                  [0.3454914689064026, 0.024471759796142578],
                                  [0.3454914689064026, 0.9755282402038574],
                                  [0.6545085906982422, 0.024471759796142578],
                                  [0.09549146890640259, 0.7938926219940186],
                                  [0.9045084714889526, 0.7938926219940186],
                                  [0.09549152851104736, 0.20610731840133667],
                                  [0.9045084714889526, 0.7938926219940186],
                                  [0.3454914689064026, 0.024471759796142578],
                                  [0.9045084714889526, 0.7938926219940186],
                                  [0.6545085906982422, 0.024471759796142578],
                                  [0.3454914689064026, 0.9755282402038574],
                                  [0.6545085906982422, 0.024471759796142578],
                                  [0.9045084714889526, 0.20610734820365906],
                                  [0.9045084714889526, 0.20610734820365906],
                                  [0.6545085906982422, 0.024471759796142578]])

    pos, line_vertices, arrows = next(layout(adjacency_mat))

    assert_allclose(pos, expected_pos, atol=1e-4)
    assert_allclose(line_vertices, expected_vertices, atol=1e-4)
コード例 #10
0
ファイル: graph.py プロジェクト: Eric89GXL/vispy
import sys

import networkx as nx

from vispy import app, scene
from vispy.visuals.graphs import layouts


canvas = scene.SceneCanvas(title='Simple NetworkX Graph', size=(600, 600),
                           bgcolor='white', show=True)
view = canvas.central_widget.add_view('panzoom')

graph = nx.adjacency_matrix(
    nx.fast_gnp_random_graph(500, 0.005, directed=True))
layout = layouts.get_layout('force_directed', iterations=100)

visual = scene.visuals.Graph(
    graph, layout=layout, line_color='black', arrow_type="stealth",
    arrow_size=30, node_symbol="disc", node_size=20,
    face_color=(1, 0, 0, 0.2), border_width=0.0, animate=True, directed=False,
    parent=view.scene)


@canvas.events.draw.connect
def on_draw(event):
    if not visual.animate_layout():
        canvas.update()

if __name__ == '__main__':
    if sys.flags.interactive != 1:
コード例 #11
0
import sys

import networkx as nx

from vispy import app, scene
from vispy.visuals.graphs import layouts

canvas = scene.SceneCanvas(title='Simple NetworkX Graph',
                           size=(600, 600),
                           bgcolor='white',
                           show=True)
view = canvas.central_widget.add_view('panzoom')

graph = nx.adjacency_matrix(nx.fast_gnp_random_graph(500, 0.005,
                                                     directed=True))
layout = layouts.get_layout('force_directed', iterations=100)

visual = scene.visuals.Graph(graph,
                             layout=layout,
                             line_color='black',
                             arrow_type="stealth",
                             arrow_size=30,
                             node_symbol="disc",
                             node_size=20,
                             face_color=(1, 0, 0, 0.2),
                             border_width=0.0,
                             animate=True,
                             directed=False,
                             parent=view.scene)

コード例 #12
0
ファイル: networkx_layout.py プロジェクト: djhoese/vispy
# -*- coding: utf-8 -*-
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
from vispy import scene
from vispy.visuals.graphs import layouts
import networkx as nx
g = nx.erdos_renyi_graph(100, .2)
layout = layouts.get_layout("networkx_layout", graph=g, layout="spring")

# create canvas
canvas = scene.SceneCanvas(title='Simple NetworkX Graph',
                           size=(600, 600),
                           bgcolor='black',
                           show=True)
view = canvas.central_widget.add_view('panzoom')
visual = scene.visuals.Graph(layout.adj,
                             layout=layout,
                             line_color=(1, 1, 1, .5),
                             arrow_type="stealth",
                             arrow_size=30,
                             node_symbol="disc",
                             node_size=20,
                             face_color=(1, 0, 0, 1),
                             border_width=0.0,
                             animate=False,
                             directed=False,
                             parent=view.scene)


@canvas.events.draw.connect
def on_draw(event):