コード例 #1
0
ファイル: draw.py プロジェクト: codejoncode/Graphs
    def show(self):
        N = len(self.graph.vertices.keys())  #length of vertices
        node_indices = list(range(N))
        plot = figure(title="Graph of Nodes and Edges",
                      x_range=(-1.1, 1.1),
                      y_range=(-1.1, 1.1),
                      tools='',
                      toolbar_location=None)

        graph = GraphRenderer()

        graph.node_renderer.data_source.add(node_indices, 'index')
        graph.node_renderer.data_source.add(Spectral8, 'color')
        graph.node_renderer.glyph = Oval(height=0.1,
                                         width=0.2,
                                         fill_color='color')

        graph.edge_renderer.data_source.data = dict(start=[0] * N,
                                                    end=node_indices)
        circ = [
            i * 2 * math.pi / len(self.graph.vertices.keys())
            for i in node_indices
        ]
        x = [math.cos(i) for i in circ]
        y = [math.sin(i) for i in circ]

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        plot.renderers.append(graph)
        output_file('graph.html')
        show(plot)
コード例 #2
0
 def make_user_graph(self, data, top_level_name, oval_height = 0.1, oval_width=0.2, branch_depth = .6, 
         top_color = Spectral8[0], second_level_color = Spectral8[1] , third_level_color = Spectral8[2],
         label_x_offset = -15, label_y_offset = 10, p =  None, 
         max_num_in_row = 5, line_width = .5
         ):
     if not p:
         p = figure(title="Test Ad Graph", x_range=(-1.1,1.1), y_range=(-1.1,1.1),
             tools="", toolbar_location=None, plot_width = 1000)
     graph = GraphRenderer()
     graph.node_renderer.glyph = Oval(height=oval_height, width=oval_width, fill_color="fill_color", name="text")
     node_indices = [x for x in range(self._make_node_indices(data))]
     second_level_pos, third_level_pos =  self._make_pos_dict(data)
     graph.node_renderer.data_source.data = dict(index=node_indices, fill_color=self._make_fill_colors(
         second_level_pos, third_level_pos,  second_level_color = second_level_color, third_level_color = third_level_color, top_color = top_color))
     eds, edge_widths, edge_colors = self._make_edges(second_level_pos, third_level_pos, data, default_width =  line_width)
     graph.edge_renderer.data_source.data = eds
     graph_layout= self._make_layout(second_level_pos = second_level_pos, third_level_pos = third_level_pos,  depth = branch_depth, 
             max_num = max_num_in_row)
     graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)
     p.add_layout(self._make_labels(graph_layout = graph_layout, second_level_pos = second_level_pos,
         third_level_pos = third_level_pos, x_offset = label_x_offset, 
         y_offset =  label_y_offset, top_level_name = top_level_name))
     graph.edge_renderer.data_source.data["line_width"] = edge_widths
     graph.edge_renderer.glyph.line_width = {'field': 'line_width'}
     graph.edge_renderer.data_source.data["line_color"] = edge_colors
     graph.edge_renderer.glyph.line_color = {'field': 'line_color'}
     p.renderers.append(graph)
     return  p
コード例 #3
0
ファイル: draw.py プロジェクト: ckopecky/Graphs
    def _setup_graph_renderer(self, circle_size, draw_components):
        #graph_renderer will have the actual logic for drawing
        graph_renderer = GraphRenderer()
        self.vertex_keys = list(self.graph.vertices.keys())

        # add the vertex data as instructions for drawing nodes
        graph_renderer.node_renderer.data_source.add(
            [vertex.label for vertex in self.vertex_keys], 'index')

        if draw_components:
            graph_renderer.node_renderer.data_source.add(
                self._get_connected_component_colors(), "color")
        else:
            graph_renderer.node_renderer.data_source.add(
                self._get_random_colors(), "color")
        graph_renderer.node_renderer.glyph = Circle(size=circle_size,
                                                    line_color="black",
                                                    fill_color="color")
        graph_renderer.edge_renderer.data_source.data = self._get_edge_indices(
        )
        self.randomize()
        self.plot.add_layout(Title(text="Whys", align="left"), "left")
        self.plot.add_layout(Title(text="Exes", align="center"), "below")
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=self.pos)
        self.plot.renderers.append(graph_renderer)
コード例 #4
0
    def show(self):
        node_indices = list(self.graph.vertices.keys())
        x_value = [x for (x, y) in self.graph.vertices.items()]
        y_value = [list(y) for (x, y) in self.graph.vertices.items()]

        plot = figure(title="Graph Layout",
                      x_range=(0, 4),
                      y_range=(0, 4),
                      tools="",
                      toolbar_location=None)

        graph = GraphRenderer()

        graph.node_renderer.data_source.add(x_value, 'index')
        graph.node_renderer.data_source.add(Spectral8, 'color')
        graph.node_renderer.glyph = Circle(radius=0.1, fill_color='color')

        print("\n x value: ", x_value)
        print("\n y value: ", y_value)

        graph.edge_renderer.data_source.data = dict(start=x_value, end=y_value)

        circ = [int(i) for i in x_value]
        x = [i for i in circ]
        y = [math.sin(i) for i in circ]  # sinus shape

        graph_layout = dict(zip(x_value, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        plot.renderers.append(graph)

        output_file('graph.html')
        show(plot)
コード例 #5
0
ファイル: RunMe.py プロジェクト: meenurajapandian/CS590-Yelp
def create_graph():
    #Find the layout and color choice
    if radio_layout.active == 0:
        lay = 'WDegreepos'
    elif radio_layout.active == 1:
        lay = 'bwcentralpos'
    else:
        lay = 'ccentralpos'

    if radio_color.active == 0:
        col = 'DegCol'
    elif radio_color.active == 1:
        col = 'Colbw'
    elif radio_color.active == 2:
        col = 'friend'
    elif radio_color.active == 3:
        col = 'reviewcount'
    else:
        col = 'comprank'

    # Create Network view
    graph = GraphRenderer()
    graph.node_renderer.data_source.data = nodes_df(G, col)
    graph.edge_renderer.data_source.data = edges_df(G)
    graph.node_renderer.glyph = Circle(size='size',
                                       fill_color='Col',
                                       line_color="black",
                                       line_alpha=0.1,
                                       fill_alpha=1)
    graph.edge_renderer.glyph = MultiLine(line_alpha='alpha',
                                          line_width=0.1,
                                          line_color="#d8b7a4")
    graph_layout = dict(nx.get_node_attributes(G, lay))
    graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

    # Glyph properties on selection
    graph.selection_policy = NodesAndLinkedEdges()
    graph.inspection_policy = EdgesAndLinkedNodes()
    graph.node_renderer.selection_glyph = Circle(size=12,
                                                 fill_color='#0A5EB6',
                                                 line_color="#002217")
    graph.edge_renderer.selection_glyph = MultiLine(line_color="#2972BE",
                                                    line_width=0.5,
                                                    line_alpha=0.4)

    # Adding graph to plot
    plot = figure(title="Yelp Users Layout",
                  x_range=(-6.5, 6.5),
                  y_range=(-6.5, 6.5),
                  plot_width=525,
                  plot_height=525,
                  toolbar_location="above")
    plot.outline_line_alpha = 0
    plot.xgrid.grid_line_color = None
    plot.ygrid.grid_line_color = None
    plot.xaxis.visible = False
    plot.yaxis.visible = False
    plot.renderers.append(graph)  # Adding graph

    return row(plot)
コード例 #6
0
    def _setup_graph_renderer(self, circle_size, draw_components):
        # The renderer will have the actual logic for drawing
        graph_renderer = GraphRenderer()
        # Saving vertices in an arbitrary but persistent order
        self.vertex_list = list(self.graph.vertices.keys())

        # Add the vertex data as instructions for drawing nodes
        graph_renderer.node_renderer.data_source.add(
            [vertex.label for vertex in self.vertex_list], 'index')
        colors = (self._get_connected_component_colors()
                  if draw_components else self._get_random_colors())
        graph_renderer.node_renderer.data_source.add(colors, 'color')
        # And circles
        graph_renderer.node_renderer.glyph = Circle(size=circle_size,
                                                    fill_color='color')

        graph_renderer.node_renderer.hover_glyph = Circle(
            size=circle_size, fill_color=Category20[20][9])
        graph_renderer.node_renderer.selection_glyph = Circle(
            size=circle_size, fill_color=Category20[20][6])

        # Add the edge [start, end] indices as instructions for drawing edges
        graph_renderer.edge_renderer.data_source.data = self._get_edge_indexes(
        )
        self.randomize()  # Randomize vertex coordinates, and set as layout
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=self.pos)

        # Attach the prepared renderer to the plot so it can be shown
        graph_renderer.selection_policy = NodesAndLinkedEdges()
        graph_renderer.inspection_policy = EdgesAndLinkedNodes()
        self.plot.renderers.append(graph_renderer)
        print(graph_renderer.node_renderer)
        tool = PointDrawTool(renderers=[graph_renderer.node_renderer])
        self.plot.add_tools(tool)
コード例 #7
0
def report_html_graph(logger, iteration=0):
    # type: (Logger, int) -> ()
    """
    reporting bokeh graph (html) to debug samples section
    :param logger: The task.logger to use for sending the plots
    :param iteration: The iteration number of the current reports
    """
    nodes = 8
    node_indices = list(range(nodes))
    plot = figure(
        title="Graph Layout Demonstration",
        x_range=(-1.1, 1.1),
        y_range=(-1.1, 1.1),
        tools="",
        toolbar_location=None,
    )
    graph = GraphRenderer()
    graph.node_renderer.data_source.add(node_indices, "index")
    graph.node_renderer.data_source.add(Spectral8, "color")
    graph.node_renderer.glyph = Oval(height=0.1, width=0.2, fill_color="color")
    graph.edge_renderer.data_source.data = dict(start=[0] * nodes,
                                                end=node_indices)
    # start of layout code
    circ = [i * 2 * math.pi / 8 for i in node_indices]
    x = [math.cos(i) for i in circ]
    y = [math.sin(i) for i in circ]
    graph_layout = dict(zip(node_indices, zip(x, y)))
    graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)
    plot.renderers.append(graph)
    output_file("graph.html")
    save(plot)
    logger.report_media("html",
                        "Graph_html",
                        iteration=iteration,
                        local_path="graph.html")
コード例 #8
0
    def _setup_graph_renderer(self, circle_size, draw_components):
        # The renderer will have the actual logic for drawing
        graph_renderer = GraphRenderer()
        # Saving vertices in an arbitrary but persistent order
        self.vertex_list = list(self.graph.vertices.values())
        # .keys is getting the key from each key-value pair in self.graph.vertices
        # Therefore, we get a list of integers
        # print(f"self.vertex_list: {self.vertex_list}")

        # Add the vertex data as instructions for drawing nodes
        graph_renderer.node_renderer.data_source.add(
            [vertex.label for vertex in self.vertex_list], 'index')
        """
        PY
        [vertex.label for vertex in self.vertex_list]
        ===
        JS
        this.vertex_list.map(vertex => vertex.label)
        """
        colors = (self._get_connected_component_colors()
                  if draw_components else self._get_random_colors())
        graph_renderer.node_renderer.data_source.add(colors, 'color')
        # And circles
        graph_renderer.node_renderer.glyph = Circle(size=circle_size,
                                                    fill_color='color')

        # Add the edge [start, end] indices as instructions for drawing edges
        graph_renderer.edge_renderer.data_source.data = self._get_edge_indexes(
        )
        self.randomize()  # Randomize vertex coordinates, and set as layout
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=self.pos)
        # Attach the prepared renderer to the plot so it can be shown
        self.plot.renderers.append(graph_renderer)
コード例 #9
0
ファイル: draw.py プロジェクト: LizBaker/Graphs
 def __init__(self, lilgraph):
     self.lilgraph = lilgraph
     self.keys = []
     self.values = []
     for key in self.lilgraph.vertices:
         for value in self.lilgraph.vertices[key].edges:
             self.keys.append(key)
             self.values.append(value)
     vertices = list(lilgraph.vertices.keys())
     plot = figure(title='One heckin graph',
                   x_range=(-1.1, 1.1),
                   y_range=(-1.1, 1.1),
                   tools='',
                   toolbar_location=None)
     graph = GraphRenderer()
     graph.node_renderer.data_source.add(vertices, 'index')
     graph.node_renderer.glyph = Oval(height=0.05,
                                      width=0.05,
                                      fill_color='pink')
     graph.edge_renderer.data_source.data = dict(start=self.keys,
                                                 end=self.values)
     circ = [i * 2 * math.pi / 8 for i in vertices]
     x = [math.cos(i) for i in circ]
     y = [math.sin(i) for i in circ]
     graph_layout = dict(zip(vertices, zip(x, y)))
     graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)
     plot.renderers.append(graph)
     show(plot)
     output_file('graph.html')
コード例 #10
0
    def _setup_graph_renderer(self, circle_size, draw_components):
        # The renderer will have the actual logic for drawing
        graph_renderer = GraphRenderer()
        # Saving vertices in an arbitrary but persistent order
        self.vertex_list = list(self.graph.vertices.keys())

        # Add the vertex data as instructions for drawing nodes
        graph_renderer.node_renderer.data_source.add(
            [vertex.label for vertex in self.vertex_list], 'index')

        print("\nRandom Colors")
        print(self._get_random_colors(len(self.vertex_list)))

        colors = (self._get_connected_component_colors() if draw_components
                  else self._get_random_colors(len(self.vertex_list)))
        graph_renderer.node_renderer.data_source.add(colors, 'color')
        # And circles
        graph_renderer.node_renderer.glyph = Circle(size=circle_size,
                                                    fill_color='color')

        # Add the edge [start, end] indices as instructions for drawing edges
        graph_renderer.edge_renderer.data_source.data = self._get_edge_indexes()
        self.randomize()  # Randomize vertex coordinates, and set as layout
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=self.pos)
        # Attach the prepared renderer to the plot so it can be shown
        self.plot.renderers.append(graph_renderer)
コード例 #11
0
ファイル: draw.py プロジェクト: Jameson13B/Graphs
    def show(self):
        node_indices = list(self.graph.keys())

        plot = figure(title="Graph Layout Render",
                      x_range=(-1.1, 10.1),
                      y_range=(-1.1, 10.1),
                      tools="",
                      toolbar_location=None)

        graph = GraphRenderer()

        graph.node_renderer.data_source.add(node_indices, 'index')
        graph.node_renderer.data_source.add(['red'] * self.size, 'color')
        graph.node_renderer.glyph = Circle(radius=0.25, fill_color='color')

        start_indices = []
        end_indices = []

        for vertex in self.graph:
            for edge_end in self.graph[vertex]:
                start_indices.append(vertex)
                end_indices.append(edge_end)

        ### start of layout code
        circ = [int(v) for v in g.vertices]
        x = [math.cos(i) for i in circ]
        y = [math.sin(i) for i in circ]

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        plot.renderers.append(graph)

        output_file('graph.html')
        show(plot)
コード例 #12
0
ファイル: draw.py プロジェクト: mykeal-kenny/Graphs
    def _setup_graph_renderer(self, circle_size):
        graph_renderer = GraphRenderer()

        graph_renderer.node_renderer.data_source.add(
            list(self.graph.vertices.keys()), "index")
        graph_renderer.node_renderer.data_source.add(self._get_random_colors(),
                                                     "color")
        graph_renderer.node_renderer.glyph = Circle(size=circle_size,
                                                    fill_color="color")
        graph_renderer.edge_renderer.data_source.data = self._get_edge_indexes(
        )
        self.randomize()
        for i in range(
                len(graph_renderer.edge_renderer.data_source.data["start"])):
            self.plot.add_layout(
                Arrow(
                    end=VeeHead(size=20, fill_color="black"),
                    x_start=self.pos[graph_renderer.edge_renderer.data_source.
                                     data["start"][i]][0],
                    y_start=self.pos[graph_renderer.edge_renderer.data_source.
                                     data["start"][i]][1],
                    x_end=self.pos[graph_renderer.edge_renderer.data_source.
                                   data["end"][i]][0],
                    y_end=self.pos[graph_renderer.edge_renderer.data_source.
                                   data["end"][i]][1],
                ))

        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=self.pos)
        self.plot.renderers.append(graph_renderer)
        self._get_labels()
コード例 #13
0
    def draw(self):
        graph = self.graph

        N = len(graph.vertices)
        node_indices = list(graph.vertices.keys())

        print(f"node indices: {node_indices}")

        plot = figure(title='Graph Layout Demonstration',
                      x_range=(-10, 10),
                      y_range=(-10, 10),
                      tools='',
                      toolbar_location=None)

        graph_renderer = GraphRenderer()

        graph_renderer.node_renderer.data_source.add(node_indices, 'index')
        # graph.node_renderer.data_source.add(Spectral8, 'color')
        graph_renderer.node_renderer.glyph = Oval(height=0.6,
                                                  width=0.5,
                                                  fill_color='red')

        graph_renderer.edge_renderer.data_source.data = dict(start=[0] * N,
                                                             end=node_indices)

        d = dict(start=[0] * N, end=node_indices)
        print(f"dict: {d}")

        ### start of layout code
        # circ = [i*2*math.pi/8 for i in node_indices]
        # x = [math.cos(i) for i in circ]
        # y = [math.sin(i) for i in circ]
        x = []
        y = []
        for vertex_id in node_indices:
            vertex = graph.vertices[vertex_id]
            x.append(vertex.x)
            y.append(vertex.y)

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=graph_layout)

        plot.renderers.append(graph_renderer)

        output_file('graph.html')
        show(plot)


# graph = Graph()  # Instantiate your graph
# graph.add_vertex('0')
# graph.add_vertex('1')
# graph.add_vertex('2')
# graph.add_vertex('3')
# graph.add_edge('0', '1')
# graph.add_edge('0', '3')
# print(graph.vertices)

# bg = BokehGraph(graph)
# bg.draw()
コード例 #14
0
ファイル: draw.py プロジェクト: lfsalazarcruz/Graphs-AH
    def show(self):
        N = len(self.graph.vertices)
        node_indices = list(self.graph.vertices.keys())

        plot = figure(title='Graph Layout Demonstration',
                      x_range=(-1.1, 1.1),
                      y_range=(-1.1, 1.1),
                      tools='',
                      toolbar_location=None)

        graph = GraphRenderer()

        graph.node_renderer.data_source.add(node_indices, 'index')
        graph.node_renderer.data_source.add(Spectral8, 'color')
        graph.node_renderer.glyph = Circle(radius=0.1, fill_color='color')

        graph.edge_renderer.data_source.data = dict(start=[0] * N,
                                                    end=node_indices)

        ### start of layout code
        circ = [i * 2 * math.pi / N for i in node_indices]
        x = [math.cos(i) for i in circ]
        y = [math.sin(i) for i in circ]

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        plot.renderers.append(graph)

        output_file('graph.html')
        show(plot)
コード例 #15
0
 def _setup_graph_renderer(self, circle_size, draw_components):
     # The renderer will have the actual logic for drawing
     graph_renderer = GraphRenderer()
     # Saving vertices in an arbitrary but persistent order
     self.vertex_keys = list(self.graph.vertices.keys())
     # Add the vertex data as instructions for drawing nodes
     graph_renderer.node_renderer.data_source.add(
         [vertex.label for vertex in self.vertex_keys], 'index')
     # Connected Components will be the same color
     # island components will be random colors
     colors = (self._color_connected_components()
               if draw_components else self._RCG())
     graph_renderer.node_renderer.data_source.add(colors, 'color')
     # give the vertice shape
     graph_renderer.node_renderer.glyph = Circle(size=circle_size,
                                                 fill_color='color')
     # Add the edge [start, end] indices as instructions for drawing edges
     graph_renderer.edge_renderer.data_source.data = self._get_edge_indexes(
     )
     # Randomize vertex coordinates, and set as layout
     self.randomize()
     # destructure this a little to squish a long line
     _layout = StaticLayoutProvider(graph_layout=self.position)
     graph_renderer.layout_provider = _layout
     # Attach the prepared renderer to the plot so it can be shown
     self.plot.renderers.append(graph_renderer)
コード例 #16
0
    def draw(self,
             title='Graph',
             width=10,
             height=10,
             show_axis=False,
             show_grid=False,
             circle_size=25):
        plot = figure(title=title, x_range=(0, width), y_range=(0, height))

        plot.axis.visible = show_axis
        plot.grid.visible = show_grid

        graph = GraphRenderer()
        graph.node_renderer.data_source.add(self._get_indices(), 'index')
        graph.node_renderer.data_source.add(self._get_colors(), 'color')
        graph.node_renderer.glyph = Circle(size=circle_size,
                                           fill_color='color')
        graph.edge_renderer.data_source.data = self._get_edges()

        self._map_coords(width, height)
        graph.layout_provider = StaticLayoutProvider(graph_layout=self.pos)
        plot.renderers.append(graph)

        labels = self._setup_labels()
        plot.add_layout(labels)

        output_file('./graph.html')
        show(plot)
コード例 #17
0
def create_decision_tree_graph_renderer(plot, tree):
    """Crea el renderizador del gráfico del árbol de decisión. Para ello se deben especificar configuraciones como: indices o identificadores
    de los nodos, colores de los nodos, tipos de figura de los nodos, tipos de figura de relación entre nodo y las relaciones entre los nodos (inicio y final).

    Parameters:
		plot (Figure): Figura Bokeh donde se muestra el árbol de decisión.
		tree (Tree): Estructura del árbol de decisión a mostrar.

    Returns:
		GraphRenderer: Renderizador del gráfico del árbol de decisión.
    """

    node_indices = [node.id for node in tree.node_list]
    node_colors = [node.color for node in tree.node_list]

    start, end = tree.get_nodes_relations()
    x, y = tree.get_layout_node_positions(plot)
    graph_layout = dict(zip(node_indices, zip(x, y)))

    graph = GraphRenderer()

    graph.node_renderer.data_source.add(node_indices, 'index')
    graph.node_renderer.data_source.add(node_colors, 'color')
    graph.node_renderer.glyph = Rect(height=0.15,
                                     width=0.2,
                                     fill_color='color')
    graph.edge_renderer.glyph = MultiLine(line_color='#b5b8bc',
                                          line_alpha=0.8,
                                          line_width=5)

    graph.edge_renderer.data_source.data = dict(start=start, end=end)

    graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

    return graph
コード例 #18
0
ファイル: draw.py プロジェクト: vanceleon/Graphs
    def draw(self):
        print('self.graph.vertices:', self.graph.vertices)
        N = len(self.graph.vertices)
        node_indices = list(self.graph.vertices.keys())
        print('node_indices:', node_indices)

        plot = figure(title="Graph Layout Demonstration",
                      x_range=(-7, 7),
                      y_range=(-7, 7),
                      tools="",
                      toolbar_location=None)

        graph = GraphRenderer()

        graph.node_renderer.data_source.add(node_indices, 'index')
        graph.node_renderer.data_source.add(Spectral5, 'color')
        graph.node_renderer.glyph = Oval(height=0.5,
                                         width=0.5,
                                         fill_color="color")

        print(f"self.keys: {self.keys} self.values: {self.values}")
        graph.edge_renderer.data_source.data = dict(start=self.keys,
                                                    end=self.values)

        ## start of layout code
        circ = [int(i) * 2 * math.pi / 8 for i in node_indices]
        x = [math.cos(i) for i in circ]
        y = [math.sin(i) for i in circ]

        # x = []
        # y = []
        # for vertex_id in node_indices:
        #     vertex = graph.vertices[vertex_id]
        #     x.append(vertex.x)
        #     y.append(vertex.y)

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        ### Draw quadratic bezier paths
        # def bezier(start, end, control, steps):
        #     return [(1-s)**2*start + 2*(1-s)*s*control + s**2*end for s in steps]

        # xs, ys = [], []
        # sx, sy = graph_layout[0]
        # steps = [i/100. for i in range(100)]
        # for node_index in node_indices:
        #     ex, ey = graph_layout[node_index]
        #     xs.append(bezier(sx, ex, 0, steps))
        #     ys.append(bezier(sy, ey, 0, steps))
        # graph.edge_renderer.data_source.data['xs'] = xs
        # graph.edge_renderer.data_source.data['ys'] = ys

        plot.renderers.append(graph)

        # labelSource
        output_file("graph.html")
        show(plot)
コード例 #19
0
    def show(self):
        """ this method makes use of the bokeh package to produce a graph in html """
        vertex_indices = list(self.graph.vertices.keys())
        print(vertex_indices[0], "starting point for traversal")
        self.graph.depth_first(vertex_indices[0])
        self.graph.breadth_first(vertex_indices[0])

        plot = figure(title="Random Generated Graph",
                      x_range=(-7, 7),
                      y_range=(-7, 7),
                      tools='',
                      toolbar_location=None)

        graph_renderer = GraphRenderer()

        graph_renderer.node_renderer.data_source.add(vertex_indices, 'index')

        edge_start = []
        edge_end = []
        for vertex_id in vertex_indices:
            for vertices_edges in self.graph.vertices[vertex_id].edges:
                edge_start.append(vertex_id)
                edge_end.append(vertices_edges)

        for vertex_id in vertex_indices:
            vertex = self.graph.vertices[vertex_id]
            self.x_coordinates.append(vertex.coordination_x)
            self.y_coordinates.append(vertex.coordination_y)
            if vertex_id in edge_start:
                self.colors_layout.append(self.connected_color)
            else:
                self.colors_layout.append(self.disconnected_color)

        graph_renderer.node_renderer.data_source.add(self.colors_layout,
                                                     'color')
        graph_renderer.node_renderer.glyph = Circle(radius=0.5,
                                                    fill_color='color')

        graph_renderer.edge_renderer.data_source.data = dict(start=edge_start,
                                                             end=edge_end)

        graph_layout = dict(
            zip(vertex_indices, zip(self.x_coordinates, self.y_coordinates)))
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=graph_layout)

        plot.renderers.append(graph_renderer)

        label_source = ColumnDataSource(data=dict(x=self.x_coordinates, y=self.y_coordinates,\
        names=[self.graph.vertices[vertex_id].value for vertex_id in self.graph.vertices]))
        labels = LabelSet(x='x', y='y', text='names', level='glyph', \
        text_align='center', text_baseline='middle', source=label_source, \
        render_mode='canvas', text_color='white')

        plot.add_layout(labels)

        output_file('random.html')
        show(plot)
コード例 #20
0
def vis2(result, d_type, G):
    if result == -1: #----- if graph is not connected!
        print("Not connected!")
    else:
        indices = set() # to store nodes
        start = [] # to store start and enf of each edge
        end = []
        edge_color = [] #to recognize output from other edges
        for item in result: #add nodes
            indices.add(item[0])
            indices.add(item[1])
        indices = list(indices)
        for node in indices: #add edges
            for v in G.neighboors[node]:
                if v in indices:
                    start.append(node)
                    end.append(v)
                    if ((node, v) in result) or ((v, node) in result): #if it's in output give it a color
                        if d_type == 't':
                            edge_color.append('red')
                        elif d_type == 'd':
                            edge_color.append('blue')
                        else:
                            edge_color.append('green')
                    else:
                        edge_color.append('black') #else it would be black
        x = []
        y = []
        for node in indices:  #convert longitude, latitude to mercator coordinates
            xy = create_coordinates(G.coord_nodes[node][0]/1000000, G.coord_nodes[node][1]/1000000)
            x.append(xy[0])
            y.append(xy[1])
        
        tile_provider = get_provider(Vendors.CARTODBPOSITRON)
        #output_notebook()
        # range bounds supplied in web mercator coordinates
        m = figure(plot_width=800, 
                   plot_height=400,
                   x_range=(min(x)-200, max(x)+200), #span of the map
                   y_range=(min(y)-200, max(y)+200),
                   x_axis_type='mercator', 
                   y_axis_type='mercator')

        m.add_tile(tile_provider)

        graph = GraphRenderer() #initializing the graph
        graph.node_renderer.data_source.add(indices, 'index')
        graph.node_renderer.glyph = Oval(height=20, width=20, fill_color='black')
        graph.edge_renderer.data_source.data = dict( start = start, end = end)
        graph.edge_renderer.data_source.add(edge_color, 'color')
        graph.edge_renderer.glyph = MultiLine(line_color='color', line_alpha=0.8, line_width=2)

        graph_layout = dict(zip(indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        m.renderers.append(graph) #assigning the graph to the map
        show(m)
コード例 #21
0
    def show(self):
        graph = self.graph
        N = len(graph.vertices)
        node_indices = list(graph.vertices)

        plot = figure(title='Graph',
                      x_range=(self.x_min, self.x_max),
                      y_range=(self.y_min, self.y_max))

        graph_renderer = GraphRenderer()

        graph_renderer.node_renderer.data_source.add(node_indices, 'index')
        graph_renderer.node_renderer.data_source.add(Spectral8[0:N], 'color')
        graph_renderer.node_renderer.glyph = Circle(radius=0.2,
                                                    fill_color='color')

        start_indices = []
        end_indices = []

        for vertex in graph.vertices:
            for other_vert in graph.vertices[vertex].edges:
                start_indices.append(vertex)
                end_indices.append(other_vert)

        graph_renderer.edge_renderer.data_source.data = dict(
            start=start_indices, end=end_indices)

        circ = [n * 2 * math.pi / 8 for n in node_indices]
        x = [math.cos(i) for i in circ]
        y = [math.sin(i) for i in circ]

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=graph_layout)

        labelSource = ColumnDataSource(
            data=dict(x=x,
                      y=y,
                      names=[
                          graph.vertices[vertex_id].value
                          for vertex_id in graph.vertices
                      ]))
        labels = LabelSet(x='x',
                          y='y',
                          text='names',
                          level='glyph',
                          text_align='center',
                          text_baseline='middle',
                          source=labelSource,
                          render_mode='canvas')

        plot.renderers.append(graph_renderer)
        plot.add_layout(labels)

        output_file('graph.html')
        show(plot)
コード例 #22
0
ファイル: graph.py プロジェクト: sh-shmss/ml_portfolio
    def make_plot(self):
        model, word, n = self.model, self.word, self.n
        G_words = self.find_similar_words(model, word, n)
        G_weights = self.find_similar_weights(model, word, n)

        N = len(G_words)
        node_indices = list(range(N))

        plot = figure(
            plot_width=500,
            plot_height=500,
            x_range=Range1d(-1.1, 1.1),
            y_range=Range1d(-1.1, 1.1),
            tools="",
            background_fill_color="white",
            x_axis_location=None,
            y_axis_location=None,
        )
        plot.title.text = "Word Similarity Graph"
        plot.xgrid.visible = False
        plot.ygrid.visible = False
        node_hover_tool = HoverTool(tooltips=[("word", "@word")])
        plot.add_tools(node_hover_tool, BoxZoomTool(), ResetTool())

        graph = GraphRenderer()
        graph.node_renderer.data_source.add(node_indices, 'index')
        graph.node_renderer.data_source.add(G_words, 'word')
        graph.node_renderer.data_source.add(G_weights, 'weight')
        graph.node_renderer.glyph = Circle(size=15, fill_color="black")
        graph.edge_renderer.data_source.data = dict(start=[0] * N,
                                                    end=node_indices)
        graph.edge_renderer.glyph = MultiLine(line_alpha=0.8,
                                              line_cap='square',
                                              line_dash='solid')

        red = Color("black")
        colors = list(red.range_to(Color("red"), N + 1))
        colors = [color.hex for color in colors]
        graph.edge_renderer.data_source.data["line_color"] = colors[1:]
        graph.edge_renderer.glyph.line_color = {'field': 'line_color'}

        graph.edge_renderer.data_source.data["line_width"] = G_weights
        graph.edge_renderer.glyph.line_width = {'field': 'line_width'}

        circ = [i * 2 * math.pi / N for i in node_indices]
        x = [math.cos(i) for i in circ]
        x[0] = 0.0
        y = [math.sin(i) for i in circ]
        y[0] = 0.65
        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        plot.renderers.append(graph)

        return plot
コード例 #23
0
def vis4(result, d_type, G):
    if result == -1:  #----- if graph is not connected!
        print("Not possible!")
    else:
        indices = set()  # to store nodes
        start = []  # to store start and end of each edge
        end = []
        start.append(result[0])
        for item in result[1:]:  #add nodes
            indices.add(item)
            start.append(item)
            end.append(item)
        start = start[:-1]
        indices = list(indices)
        x = []
        y = []
        for node in indices:  #convert longitude, latitude to mercator coordinates
            xy = create_coordinates(G.coord_nodes[node][0] / 1000000,
                                    G.coord_nodes[node][1] / 1000000)
            x.append(xy[0])
            y.append(xy[1])

        tile_provider = get_provider(Vendors.CARTODBPOSITRON)
        #output_notebook()
        # range bounds supplied in web mercator coordinates
        m = figure(
            plot_width=800,
            plot_height=400,
            x_range=(min(x) - 200, max(x) + 200),  #span of the map
            y_range=(min(y) - 200, max(y) + 200),
            x_axis_type='mercator',
            y_axis_type='mercator')

        m.add_tile(tile_provider)

        graph = GraphRenderer()  #initializing the graph
        graph.node_renderer.data_source.add(indices, 'index')
        edge_color = 'black'
        if d_type == 'd':
            edge_color = 'blue'
        elif d_type == 't':
            edge_color = 'yellow'
        elif d_type == 'n':
            edge_color = 'green'
        graph.node_renderer.glyph = Oval(height=20, width=20, fill_color='red')
        graph.edge_renderer.data_source.data = dict(start=start, end=end)
        graph.edge_renderer.glyph = MultiLine(line_color=edge_color,
                                              line_alpha=0.8,
                                              line_width=2)

        graph_layout = dict(zip(indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        m.renderers.append(graph)  #assigning the graph to the map
        show(m)
コード例 #24
0
    def show(self):
        # color1 = [Viridis256[1]]*len(self.vertices)
        # color2 = Viridis10 
        # currentcolor = color1
        colors = [] # [orange, white, ]
        i=random.randint(0,256)
        for g in self.graphIn.groups:
            colors += [Viridis256[i]] * len(g)
            i=random.randint(0,256)  
                          
        print(colors)
        node_indices = self.vertices
        plot = figure(title='Graph Layout Demonstration',
                      x_range=(-1.1, 1.1), y_range=(-1.1, 1.1),
                      tools='', toolbar_location=None)
                      
        graph = GraphRenderer()
        graph.node_renderer.data_source.add([vertex for subgroup in self.graphIn.groups for vertex in subgroup], 'index') #               [6,7,1,2,3,4,5]
        graph.node_renderer.data_source.add(colors, 'color') #graph.groups = [[6], [7], [1,2,3,4,5]]   [orange, purp, gray, gray, gray, gray, gray]
        graph.node_renderer.glyph = Circle(radius=0.1, fill_color='color', name=str(node_indices))

        starts = []
        for k in self.graphIn.vertices.keys():
            starts += [k]*(len(self.graphIn.vertices[k]))
        ends = []
        for k, v in self.graphIn.vertices.items():
            ends += v
        graph.edge_renderer.data_source.data = dict(
            start=starts,
            end=ends)

        circ = [int(i)*2*math.pi/len(self.vertices) for i in node_indices]
        x = [math.cos(i) for i in circ]
        y = [math.sin(i) for i in circ]

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        # setup labels
        data = {
                'x': x,
                'y': y,
                'name': node_indices
            }
        source = ColumnDataSource(data)
        labels = LabelSet(x="x", y="y", text="name", y_offset=-5,
                          text_font_size="12pt", text_color="white",
                          source=source, text_align='center')

        plot.add_layout(labels)
        plot.renderers.append(graph)

        output_file('graph2.html')
        show(plot)
コード例 #25
0
ファイル: draw.py プロジェクト: ekm79/Graphs
    def show(self):
        node_indices = list(self.graph.vertices)
        #x_value = [x for (x, y) in self.graph.vertices]
        #y_value = [y for (x, y) in self.graph.vertices]

        plot = figure(title="Graph Layout",
                      x_range=(-2, 10),
                      y_range=(-2, 10),
                      tools="",
                      toolbar_location=None)

        graph = GraphRenderer()

        graph.node_renderer.data_source.add(node_indices, 'index')
        graph.node_renderer.data_source.add(Spectral8, 'color')
        graph.node_renderer.glyph = Circle(radius=0.3, fill_color='color')

        #print("\n x value: ", x_value)
        #print("\n y value: ", y_value)

        start_indices = []
        end_indices = []

        for vertex_id in self.graph.vertices:
            for edge_end in self.graph.vertices[vertex_id].edges:
                start_indices.append(vertex_id)
                end_indices.append(edge_end)

        graph.edge_renderer.data_source.data = dict(start=start_indices,
                                                    end=end_indices)

        grid = [int(i) for i in self.graph.vertices]
        x = [self.graph.vertices[node].x for node in self.graph.vertices]
        y = [self.graph.vertices[node].y for node in self.graph.vertices]

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        plot.renderers.append(graph)

        labelSource = ColumnDataSource(data=dict(x=x, y=y, names=grid))
        labels = LabelSet(x='x',
                          y='y',
                          text='names',
                          level='glyph',
                          text_align='center',
                          text_baseline='middle',
                          source=labelSource,
                          render_mode='canvas')
        plot.add_layout(labels)

        output_file('graph.html')
        show(plot)
コード例 #26
0
    def _setup_graph_renderer(self, circle_size):
        graph_renderer = GraphRenderer()

        graph_renderer.node_renderer.data_source.add(
            list(self.graph.vertices.keys()), 'index')
        graph_renderer.node_renderer.data_source.add(
            self._get_random_colors(), 'color')
        graph_renderer.node_renderer.glyph = Circle(size=circle_size, fill_color='color')
        graph_renderer.edge_renderer.data_source.data = self._get_edge_indexes()
        self.randomize()
        graph_renderer.layout_provider = StaticLayoutProvider(graph_layout=self.pos)
        self.plot.renderers.append(graph_renderer)
コード例 #27
0
    def show(self):
        N = len(graph.vertices)
        node_indices = list(graph.vertices)
        plot = figure(title='Graph',
                      x_range=(-2, 5),
                      y_range=(-2, 5),
                      tools='',
                      toolbar_location=None)
        graph_renderer = GraphRenderer()
        graph_renderer.node_renderer.data_source.add(node_indices, 'index')
        graph_renderer.node_renderer.data_source.add(
            [v.color for v in graph.vertices], 'color')
        graph_renderer.node_renderer.glyph = Circle(radius=0.2,
                                                    fill_color='color')

        start_indices = []
        end_indices = []

        for vertex_id in graph.vertices:
            for edge_end in graph.vertices[vertex_id]:
                start_indices.append(vertex_id)
                end_indices.append(edge_end)
        graph_renderer.edge_renderer.data_source.data = dict(
            start=start_indices, end=end_indices)

        # start of layout code
        grid = [int(v) for v in graph.vertices]
        x = [graph.vertices[vertex_id].x for vertex_id in graph.vertices]
        y = [graph.vertices[vertex_id].y for vertex_id in graph.vertices]
        # x = [i for i in grid]
        # y = [i ** 2 for i in grid]

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=graph_layout)

        plot.renderers.append(graph_renderer)

        labelSource = ColumnDataSource(data=dict(x=x, y=y, names=grid))
        labels = LabelSet(x='x',
                          y='y',
                          text='names',
                          level='glyph',
                          text_align='center',
                          text_baseline='middle',
                          source=labelSource,
                          render_mode='canvas')

        plot.add_layout(labels)

        output_file('graph.html')
        show(plot)
コード例 #28
0
ファイル: draw.py プロジェクト: munsu99/Graphs
    def draw(self):
        graph = self.graph
        N = len(graph.vertices)
        node_indices = list(graph.vertices.keys())

        print(node_indices)

        plot = figure(title='Graph Layout Demonstration',
                      x_range=(-7, 7),
                      y_range=(-7, 7),
                      tools='',
                      toolbar_location=None)

        graph_renderer = GraphRenderer()

        graph_renderer.node_renderer.data_source.add(node_indices, 'index')
        node_colors = [
            'red', 'blue', 'green', 'yellow', 'black', 'pink', 'purple',
            'white'
        ]
        graph_renderer.node_renderer.data_source.add(node_colors, 'color')
        graph_renderer.node_renderer.glyph = Rect(height=0.1,
                                                  width=0.2,
                                                  fill_color='color')

        graph_renderer.edge_renderer.data_source.data = dict(start=[0] * N,
                                                             end=node_indices)

        d = dict(start=[0] * N, end=node_indices)
        print(d)

        # start of layout code
        # circ = [i*2*math.pi/8 for i in node_indices]
        # x = [math.cos(i) for i in circ]
        # y = [math.sin(i) for i in circ]

        x = []
        y = []
        for vertex_id in node_indices:
            vertex = graph.vertices[vertex_id]
            x.append(vertex.x)
            y.append(vertex.y)

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=graph_layout)

        plot.renderers.append(graph_renderer)

        output_file('graph.html')
        show(plot)
コード例 #29
0
    def draw(self):
        graph = self.graph

        N = len(graph.vertices)
        node_indices = list(graph.vertices.keys())

        plot = figure(title="Graph Layout Demonstration",
                      x_range=(-7, 7),
                      y_range=(-7, 7),
                      tools="",
                      toolbar_location=None)

        graph_renderer = GraphRenderer()

        graph_renderer.node_renderer.data_source.add(node_indices, 'index')
        # node_colors = ['red'] * N
        # graph.node_renderer.data_source.add(node_colors, 'color')
        graph_renderer.node_renderer.glyph = Circle(radius=0.5,
                                                    fill_color="red")

        edge_start = []
        edge_end = []

        # O(E), where E is the total number of edges
        for vertex_id in node_indices:
            for v in graph.vertices[vertex_id].edges:
                edge_start.append(vertex_id)
                edge_end.append(v)

        graph_renderer.edge_renderer.data_source.data = dict(start=edge_start,
                                                             end=edge_end)

        # start of layout code
        # circ = [i*2*math.pi/8 for i in node_indices]
        # x = [math.cos(i) for i in circ]
        # y = [math.sin(i) for i in circ]
        x = []
        y = []
        for vertex_id in node_indices:
            vertex = graph.vertices[vertex_id]
            x.append(vertex.x)
            y.append(vertex.y)

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=graph_layout)

        plot.renderers.append(graph_renderer)

        output_file('graph.html')
        show(plot)
コード例 #30
0
ファイル: draw.py プロジェクト: NickolausSmith/Graphs
    def show(self):
        node_indices = self.vertices
        endpoints = self.endpoints
        plot = figure(title='Graph Layout Demonstration',
                      x_range=(-1.1, 1.1),
                      y_range=(-1.1, 1.1),
                      tools='',
                      toolbar_location=None)

        graph = GraphRenderer()
        graph.node_renderer.data_source.add(node_indices, 'index')
        graph.node_renderer.data_source.add(Viridis10, 'color')
        graph.node_renderer.glyph = Circle(radius=0.1,
                                           fill_color='color',
                                           name=str(node_indices))

        starts = []
        for k in self.graphIn.vertices.keys():
            starts += [k] * (len(self.graphIn.vertices[k]))
        ends = []
        for k, v in self.graphIn.vertices.items():
            ends += v
        graph.edge_renderer.data_source.data = dict(start=starts, end=ends)

        circ = [
            int(i) * 2 * math.pi / len(self.vertices) for i in node_indices
        ]
        x = [math.cos(i) for i in circ]
        y = [math.sin(i) for i in circ]

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        #setup labels
        data = {'x': x, 'y': y, 'name': node_indices}
        source = ColumnDataSource(data)
        labels = LabelSet(x="x",
                          y="y",
                          text="name",
                          y_offset=-5,
                          text_font_size="12pt",
                          text_color="white",
                          source=source,
                          text_align='center')

        plot.add_layout(labels)
        plot.renderers.append(graph)

        output_file('graph2.html')
        show(plot)
コード例 #31
0
import math

from bokeh.io import show, output_file
from bokeh.plotting import figure
from bokeh.models import GraphRenderer, StaticLayoutProvider, Oval
from bokeh.palettes import Spectral8

N = 8
node_indices = list(range(N))

plot = figure(title="Graph Layout Demonstration", x_range=(-1.1,1.1), y_range=(-1.1,1.1),
              tools="", toolbar_location=None)

graph = GraphRenderer()

graph.node_renderer.data_source.data = dict(
    index=node_indices,
    fill_color=Spectral8)
graph.node_renderer.glyph = Oval(height=0.1, width=0.2, fill_color="fill_color")

graph.edge_renderer.data_source.data = dict(
    start=[0]*N,
    end=node_indices)

### start of layout code
circ = [i*2*math.pi/8 for i in node_indices]
x = [math.cos(i) for i in circ]
y = [math.sin(i) for i in circ]
graph_layout = dict(zip(node_indices, zip(x, y)))
graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)