def generate_plot(topology_file): graph = Graph("topology", filename='topology.gv', engine='neato') # graph = Graph("topology", filename='topology.gv', engine='neato', outputorder = 'breadthfirst') delay_re = "[0-9]+.0ms" server_id = "" # Add color to server node # Add color to client node with open(topology_file) as f: for line in f.readlines(): if "large" in line: line = line.replace("tb-set-hardware $node", "") server_id = line[0] if line.startswith("set linkClient"): line = line.replace("set linkClient", "") node = server(line[0], server_id) client = "ClientPool-" + line[0] add_node(graph, node) add_node(graph, client) add_edge(graph, node, client, client_edge, str(1)) elif line.startswith("set link"): line = line.replace("set link", "") node_one = server(line[0], server_id) node_two = server(line[1], server_id) add_node(graph, node_one) add_node(graph, node_two) label = re.findall(delay_re, line)[0] add_edge(graph, node_one, node_two, node_edge, label) print(graph.source) graph.save() graph.render('topology') return graph
def plot(self, render=False, save=False, filename=None): if filename is None: filename = "decision_tree.svg" dot = Graph(name="decision_tree", filename=filename, format="svg") dot.node( str(id(self)), self.splitting_info_to_string() + "\nestimate:" + str(round(float(self.value), 3)), ) for i in range(self.depth): nodes = DecisionTree.get_level_in_list(self, i + 1) for node in nodes: if node.left_child is None: dot.node( str(id(node)), "This node is not split" + "\nestimate:" + str(round(float(node.value), 3)), ) dot.edge(str(id(node.parent)), str(id(node))) else: dot.node( str(id(node)), node.splitting_info_to_string() + "\nestimate:" + str(round(float(node.value), 3)), ) dot.edge(str(id(node.parent)), str(id(node))) if render: dot.render(view=True) if save: dot.save() return dot
def constGraph(): for i in range(0, len(atom_id_input_arr)): atom_id_row = atom_id_input_arr[i] atom_output_row = atom_output_arr[i] orange_indices_row = orange_indices_arr[i] neighbour_row = neighbour_list[i] print(cod[i]) g = Graph('G', filename=str(cod[i]) + '.gv') for j in range(0, len(atom_id_row)): # print(j) if j in orange_indices_row: g.attr('node', style='filled', color='orange') else: g.attr('node', style='filled', color='white') g.node(str(j), label=atom_id_row[j]) for j in range(0, len(atom_id_row)): # print(j) for k in range(0, len(neighbour_row[j])): if not neighbour_row[j][k] == -1: g.edge(str(j), str(neighbour_row[j][k])) # g.view() g.save(filename='./' + str(cod[i]) + '.dot')
def main(): """ Main """ print("Content-type: text/html\r\n\r\n") personnages = retreive_personnnages() groupes = retreive_groupes() trames = retreive_trames() geographies = retreive_geographie() materiels = retreive_materiels() link_to_nomgraph = build_link_to_nom_graph_dict(personnages, groupes, trames, geographies, materiels) dot = Graph(name='Dragons', filename='./tmp/derniersDragons.gv', comment='Les Derniers Dragons', strict=True) add_nodes_types_shape(dot, personnages) add_nodes_types_shape(dot, groupes) add_nodes_types_shape(dot, trames) add_nodes_types_shape(dot, geographies) add_nodes_types_shape(dot, materiels) add_link_personnages(dot, link_to_nomgraph, personnages) add_link_groupes(dot, link_to_nomgraph, groupes) add_link_trames(dot, link_to_nomgraph, trames) add_link_geographie(dot, link_to_nomgraph, geographies) add_link_materiels(dot, link_to_nomgraph, materiels) dot.save() print("done")
def generateGraph(): G = Graph( engine = 'dot', filename = 'Btrfs-Graph.dot', name = 'BRTFS-Browser', comment = 'https://github.com/Zo0MER/BRTFS-Browser.git', graph_attr = {'rankdir': 'RL', 'charset':'utf-8', 'bgcolor':'#eeeeee', 'labelloc':'t', 'splines':'compound', 'nodesep':'0.7', 'ranksep':'5' }, node_attr = {'fontsize': '18.0', 'shape':'box' } ) #node with title and hyperlink on github G.node('meta', label = 'Btrfs-debug-tree \nhttps://github.com/Zo0MER/BRTFS-Browser.git', href = 'https://github.com/Zo0MER/BRTFS-Browser.git', fontcolor = '#4d2600', fontsize = '30.0' ) first = inode[0] inode.remove(inode[0]) if (inode): #link first item ROOT_TREE_DIR INODE_ITEM, INODE_REF with all INODE_ITEM EXTEND_DATA for pair in inode: G.edge(''.join([str(x) for x in first]), ''.join([str(x) for x in pair])) else: G.node(first) #save *.dot and others pathout = enterPath.get() filenameout = enterFilename.get() if (filenameout): filenameout = filenameout + '.gv.dot' else: filenameout = "btrfs-graph" G.filename = filenameout + '.gv.dot' G.directory = pathout G.save() for t in types: G.format = t G.render()
def plot(self, render=False, save=False, filename=None): """Plotting function that nicely visualizes the information contained in the class by creating an (upside-down) tree-like structure plot. Inner nodes contain information on the splitting process of the feature space while leafs contain information on treatment predictions in regions of the partition. :param tree: CausalTree: Fitted tree. :param filename: str: Name of file that should be created. :param save: bool: Should the file be saved to disk. """ if not self.is_fitted: print("The tree must be fitted in order to be plotted") return if filename is None: filename = "causal_tree.svg" dot = Graph(name="causal_tree", filename=filename, format="svg") dot.node( str(id(self)), self.splitting_info_to_string() + "\nestimate:" + str(round(float(self.value), 3)), ) for i in range(self.depth): nodes = self.get_level_in_list(i + 1) for node in nodes: if node.left_child is None: dot.node( str(id(node)), "This node is not split" + "\nestimate:" + str(round(float(node.value), 3)), ) dot.edge(str(id(node.parent)), str(id(node))) else: dot.node( str(id(node)), node.splitting_info_to_string() + "\nestimate:" + str(round(float(node.value), 3)), ) dot.edge(str(id(node.parent)), str(id(node))) if render: dot.render(view=True) if save: dot.save() return dot
def ExportToDOT(self, filename="gViz.dot", comparison_type="tokens", output="build"): ''' Creates Graphviz graph out of graph nodes and edges. The comparison type will be which similarity measure you want to use to compare sentences. By default, will only create the dot file. If output="view", it will also show the render of the graph. ''' comp = comparison_type # initialize empty graphviz graph gViz = Graph("gViz", filename=filename, engine="dot") # add all nodes in g to gViz i = 0 for node in tqdm(list(self.getVertices())): if comp == "tokens": label = node.tokens elif comp == "lemmas": label = node.lemmas elif comp == "tagged_tokens": label = node.tagged_tokens elif comp == "tagged_lemmas": label = node.tagged_lemmas gViz.node(str(i), str(label)) i += 1 # add all edge weights in g to gViz i = 0 # node1 in gViz x = 0 # node1 in g for node1 in tqdm(self.getVertices()): #print("Adding edges for node", x) j = 0 # node2 in gViz y = 0 # node2 in g for node2 in self.getVertices(): try: gViz.edge(str(i), str(j), label=str( self.getVertex(list( self.getVertices())[x]).getWeight( self.getVertex( list(self.getVertices())[y])))) y += 1 except: y += 1 j += 1 i += 1 x += 1 if output == "view": return gViz.view() else: return gViz.save()
from graphviz import Graph dot = Graph(comment='Graph') n = input("Enter no.of Edges : ") for i in range(0, n): edge = raw_input().split(' ') dot.edge(edge[0], edge[1], label=edge[2]) print(dot.source) dot.save('file.gv') dot.render('file.gv', view=True) '''Sample Input ,Format : node1 node2 label_of_edge Enter no.of Edges : 5 1 1 a 1 2 b 1 2 c 2 3 d 1 3 e '''
''' Program to identify the type of graph ''' from graphviz import Graph dot = Graph(comment='Simple Graph') edges = [] n = input("Enter no.of Edges : ") for i in range(0, n): edge = raw_input().split(' ') dot.edge(edge[0], edge[1], label=edge[2]) edges.append((edge[0], edge[1])) if len(edges) != len(set(edges)): dot.comment = "Multi Graph" for edge in edges: if edge[0] == edge[1]: dot.comment = "Pseudo Graph" break print dot.source dot.save('file') dot.render('file', view=True)
table = '<TABLE><TR><TD COLSPAN="2"><B>Hypernyms</B></TD></TR>%s</TABLE>' % table_rows avg_C = nx.average_clustering(G, weight='weight') gv = Graph(comment='Cluster {:s} for {:s}'.format(cid, ', '.join(hypernyms[cid])), encoding='utf-8', engine='sfdp', format='svg') gv.body.append('label="Graph for {:s}, average C={:.4f}"'.format(cid, avg_C)) gv.body.append('size="10,10"') gv.body.append('outputorder=edgesfirst') gv.body.append('overlap=false') gv.body.append('splines=true') gv.node_attr.update(color='#ffffff', margin='0') gv.edge_attr.update(color='#666666') gv.node('Legend', label='<{:s}>'.format(table), shape='none', margin='0') for n in G: gv.node(n) for e1, e2, data in G.edges(data=True): gv.edge(e1, e2, weight=str(data['weight'])) if len(G.edges()) > 5000: logging.warn('No reason to render such a big graph, so I will not') gv_path = gv.save(prefix + '.gv') logging.info('Graph is saved: %s', gv_path) else: gv_path = gv.render(prefix + '.gv') logging.info('Graph is rendered: %s', gv_path)
def main(restricted=False): global styles #gc.set_debug(gc.DEBUG_LEAK) site = input("What site to crawl?") maxDepth = int(input("Max depth?")) http = httplib2.Http() links = set() pages = set() #dot = Digraph(comment = site, format="png") dot = Graph(comment=site, format="png", engine="sfdp") dot.overlap = "true" #dot.graph_attr.update(size = "10000000,10000000") try: soup = BeautifulSoup(urllib2.urlopen(site), "html.parser") pageTitle = soup.title.string pages.add(pageTitle) titles[site] = pageTitle soup.decompose() except Exception as e: pageTitle = site print("Error: {0}".format(e)) siteBase = "" try: pos1 = site.find(".") pos2 = site.find(".", pos1 + 1) siteBase = site[pos1 + 1:pos2] except Exception as e: print("Error: {0}".format(e)) print(siteBase) crawlPage(site, pageTitle, maxDepth, pages, links, restricted, siteBase) #print(pages) #print(links) #for p in pages: #print("Adding node: " + p) #dot.node(p) for l in links: try: #print("Adding edge: " + l[0] + " -> " + l[1]) dot.edge(l[0], l[1]) except Exception as e: print("Error: {0}".format(e)) #print(dot) #dot = apply_styles(dot, styles) loc = str(dot).find("{") + 1 dot = Source(str(dot)[0:loc] + "\n\tgraph [overlap = prism]\n" + str(dot)[loc:], format="png", engine="sfdp") #print("-------------------") filename = r'C:\Users\Gabe\Miniconda3\MyScripts\test-crawler15' dot.save() try: os.remove(filename) except Exception as e: print("Error: {0}".format(e)) try: outFile = open(filename + ".txt", "w") outFile.write(str(dot)) outFile.close() except Exception as e: print("Error: {0}".format(e)) dot.render(filename, view=True)
from graphviz import Graph dot = Graph(comment='Graph') n = input("Enter no of Edges : ") for i in range(0,n): edge = raw_input().split(' ') dot.edge(edge[0],edge[1],label=edge[2]) print(dot.source) # dot.save('file.gv') dot.save('output.gv') #dot.render('file.gv', view=True) dot.render('output.gv', view=True) '''Sample Input ,Format : node1 node2 label_of_edge Enter no of Edges : 5 1 1 a 1 2 b 1 2 c 2 3 d 1 3 e '''
def main(restricted = False): global styles #gc.set_debug(gc.DEBUG_LEAK) site = input("What site to crawl?") maxDepth = int(input("Max depth?")) http = httplib2.Http() links = set() pages = set() #dot = Digraph(comment = site, format="png") dot = Graph(comment = site, format="png", engine="sfdp") dot.overlap = "true" #dot.graph_attr.update(size = "10000000,10000000") try: soup = BeautifulSoup(urllib2.urlopen(site), "html.parser") pageTitle = soup.title.string pages.add(pageTitle) titles[site] = pageTitle soup.decompose() except Exception as e: pageTitle = site print("Error: {0}".format(e)) siteBase = "" try: pos1 = site.find(".") pos2 = site.find(".", pos1 + 1) siteBase = site[pos1+1:pos2] except Exception as e: print("Error: {0}".format(e)) print (siteBase) crawlPage(site, pageTitle, maxDepth, pages, links, restricted, siteBase) #print(pages) #print(links) #for p in pages: #print("Adding node: " + p) #dot.node(p) for l in links: try: #print("Adding edge: " + l[0] + " -> " + l[1]) dot.edge(l[0], l[1]) except Exception as e: print("Error: {0}".format(e)) #print(dot) #dot = apply_styles(dot, styles) loc = str(dot).find("{")+1 dot = Source(str(dot)[0:loc] + "\n\tgraph [overlap = prism]\n" + str(dot)[loc:], format="png", engine="sfdp") #print("-------------------") filename = r'C:\Users\Gabe\Miniconda3\MyScripts\test-crawler15' dot.save() try: os.remove(filename) except Exception as e: print("Error: {0}".format(e)) try: outFile = open(filename + ".txt", "w") outFile.write(str(dot)) outFile.close() except Exception as e: print("Error: {0}".format(e)) dot.render(filename, view=True)