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_node(self, graph, article): """Create pygraph node""" graph.add_node(article.id) graph.add_node_attribute(article.id,{ 'name':article.slug, 'data':{} })
def AddNodeAndEdge(graph, nodeLst): for node in nodeLst: if not graph.has_node(node): graph.add_node(node) i = 0 while i < len(nodeLst)-1: if not graph.has_edge((nodeLst[i],nodeLst[i+1])): graph.add_edge((nodeLst[i],nodeLst[i+1])) i += 1
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)
def drawGraphFromSM2(SM, names, outFile, Cut): graph = pydot.Dot(graph_type='graph') # THRESHOLD SM: nonZeroMean = np.mean(SM[SM.nonzero()]) if Cut: T = 5.0 * nonZeroMean else: T = 0.0; for i in range(SM.shape[0]): for j in range(SM.shape[0]): if SM[i,j] <= T: SM[i,j] = 0.0 else: SM[i,j] = 1.0 numOfConnections = sum(SM, axis = 0) #fig = plt.figure(1) #plot1 = plt.imshow(SM, origin='upper', cmap=cm.gray, interpolation='nearest') #plt.show() numOfConnections = 9*numOfConnections / max(numOfConnections) for i,f in enumerate(names): if sum(SM[i,:])>0: fillColorCurrent = "{0:d}".format(int(ceil(numOfConnections[i]))) # NOTE: SEE http://www.graphviz.org/doc/info/colors.html for color schemes node = pydot.Node(f, style="filled", fontsize="8", shape="egg", fillcolor=fillColorCurrent, colorscheme = "reds9") graph.add_node(node) for i in range(len(names)): for j in range(len(names)): if i<j: if SM[i][j] > 0: #gr.add_edge((names[i], names[j])) edge = pydot.Edge(names[i], names[j]) graph.add_edge(edge) graph.write_png(outFile)
def create_node(self, graph, article): graph.add_node(article.id) graph.add_node_attribute(article.id,{ 'name':article.slug, 'data':{} })