def render_graph_color(graph_object,filename_str): import pydot node_list, adjacency_matrix = graph_object.labels, graph_object.adjacency_matrix if not (adjacency_matrix.shape[0] == adjacency_matrix.shape[1]): raise Exception("adjacency matrix should be square") if not (len(node_list) == adjacency_matrix.shape[0]): raise Exception("number of nodes is inconsistent with the number of available node labels") if is_directed(adjacency_matrix): graph = pydot.Dot(graph_type='digraph') else: graph = pydot.Dot(graph_type='graph') nodes_dot=[] for n in node_list: tmp = pydot.Node(n) nodes_dot.append(tmp) graph.add_node(tmp) for (i,j) in get_indices(adjacency_matrix): graph.add_edge(pydot.Edge(nodes_dot[i], nodes_dot[j], label=graph_object.property_str, labelfontcolor="#009933", fontsize="10.0", color=graph_object.edge_color)) name = "%s.png" % filename_str graph.write_png(name)
def create_graph(nodes_list, adjacency_matrix, label_str = ""): if not (adjacency_matrix.shape[0] == adjacency_matrix.shape[1]): raise Exception("adjacency matrix should be square") if not (len(nodes_list) == adjacency_matrix.shape[0]): raise Exception("number of nodes is inconsistent with the number of available node labels") if is_directed(adjacency_matrix): gr = digraph() else: gr = graph() adjacency_matrix = np.triu(adjacency_matrix) gr.add_nodes(nodes_list) for (x,y) in get_indices(adjacency_matrix): gr.add_edge((nodes_list[x],nodes_list[y]),label = label_str) return gr
def render_multi_prop_graph(multi_prop_graph,filename_str): node_list, adjacency_matrix = multi_prop_graph.labels, multi_prop_graph.adjacency_matrix if not (adjacency_matrix.shape[0] == adjacency_matrix.shape[1]): raise Exception("adjacency matrix should be square") if not (len(node_list) == adjacency_matrix.shape[0]): raise Exception("number of nodes is inconsistent with the number of available node labels") if is_directed(adjacency_matrix): graph = pydot.Dot(graph_type='digraph') direction = 'forward' else: graph = pydot.Dot(graph_type='graph',compound='true',mindist='0',ranksep='0',nodesep='0') direction = 'none' nodes_dot=[] for n in node_list: tmp = pydot.Node(n) nodes_dot.append(tmp) graph.add_node(tmp) y = deepcopy(adjacency_matrix) for (i,j) in get_indices(y): if y[i][j] == 1: if y[j][i] ==1: y[j][i] =0 direction = 'none' graph.add_edge(pydot.Edge(nodes_dot[i], nodes_dot[j], label=multi_prop_graph.property_str, labelfontcolor="#009933", fontsize="10.0", dir=direction,color=multi_prop_graph.edge_colormap[node_list[i],node_list[j]])) if is_directed(adjacency_matrix) : direction = 'forward' name = "%s.png" % filename_str #graph = add_legend(graph, property_colormap) graph.write_png(name)