def __init__(self, fname, interactive=True): self.fname = fname self.graph = nx.read_gpickle(fname) #apply_workaround(self.graph, thr=1e-3) #remove_intersecting_edges(self.graph) print "Number of connected components:", \ nx.number_connected_components(self.graph) self.selected_path_verts = [] if interactive: self.fig = plt.figure() self.path_patch = None G_p = nx.connected_component_subgraphs(self.graph)[0] #G_p = nx.connected_component_subgraphs(prune_graph(self.graph))[0] plot.draw_leaf(G_p, fixed_width=True) plt.ion() plt.show() self.edit_loop()
def randomize(self): #for n, d in self.graph.nodes_iter(data=True): # d['x'] += 10*(numpy.random.random() - 0.5) # d['y'] += 10*(numpy.random.random() - 0.5) # d['x'] = 1.3*d['x'] + 0.5*d['y'] # d['y'] = 1*d['y'] for u, v, d in self.graph.edges_iter(data=True): d['conductivity'] += 5 + 0.25*(numpy.random.random()-0.5) plt.clf() plot.draw_leaf(self.graph) plt.show()
def plot_DeltaF_in_leaf(DeltaF, G_pruned, ax=None, fixed_width=False): # plot DeltaF cmap = plt.get_cmap('jet') norm = colors.LogNorm(vmin=1e-8, vmax=1) scalar_map = cmx.ScalarMappable(norm=norm, cmap=cmap) if ax == None: plt.figure() ax = plt.gca() # unweighted scalar_map.set_array(DeltaF) cols = list(enumerate(scalar_map.to_rgba(DeltaF))) plot.draw_leaf(G_pruned, ax=ax, mark_edges=cols, fixed_width=fixed_width) ax.autoscale(tight='true')
def __init__(self, fname, interactive=True): self.fname = fname self.graph = nx.read_gpickle(fname) print "Number of connected components:", \ nx.number_connected_components(self.graph) self.selected_path_verts = [] if interactive: self.fig = plt.figure() self.path_patch = None plot.draw_leaf(self.graph) plt.ion() plt.show() self.edit_loop()
def remove_selection(self): if len(self.selected_path_verts) == 0: print "Nothing selected!" return path = self.points_to_path(close=True) nodes = [n for n in self.graph.nodes_iter() if path.contains_point((self.graph.node[n]['x'], self.graph.node[n]['y']))] print nodes self.graph.remove_nodes_from(nodes) plt.clf() plot.draw_leaf(self.graph) self.selected_path_verts = [] self.path_patch = None plt.show()
def straighten_path(self): print """Please select the edges you would like to straighten out. Available commands: l: Linear curve fit p: Print edge list x: Exit """ self.edges = self.graph.edges() self.edge_paths = [[(self.graph.node[e[0]]['x'], self.graph.node[e[0]]['y']), (self.graph.node[e[1]]['x'], self.graph.node[e[1]]['y'])] for e in self.edges] self.selected_edges = [] self.drawn_edges = [] self.cid_path_click = self.fig.canvas.mpl_connect( 'button_press_event', self.onclick_straighten_path) while True: cmd = raw_input("SP> ") if cmd == 'l': self.fit_selected_edges_linear() print "Linear fit concluded. Exiting." plt.clf() plot.draw_leaf(self.graph) self.fig.canvas.mpl_disconnect(self.cid_path_click) return elif cmd == 'x': # Clean up self.fig.canvas.mpl_disconnect(self.cid_path_click) return elif cmd == 'p': print [self.edges[e] for e in self.selected_edges] else: print "Command not recognized."
filtration_steps=args.filtration_steps) print "Decomp. took {}s.".format(time.time() - t0) print "Number of loops:", dual.number_of_nodes() print "Number of tree nodes:", tree.number_of_nodes() if args.save != "": print "Saving file." SAVE_FORMAT_VERSION = 5 sav = {'version':SAVE_FORMAT_VERSION, \ 'leaf':leaf, 'tree':tree, 'dual':dual, \ 'filtration':filtr, 'pruned':pruned, \ 'removed-edges':removed_edges} storage.save(sav, args.save) print "Done." if args.plot: plt.figure() plot.draw_leaf(leaf, "Input leaf data") plt.figure() plot.draw_leaf(pruned, "Pruned leaf data and dual graph") plot.draw_dual(dual) plt.figure() plot.draw_tree(tree) plt.figure() plot.draw_filtration(filtr) plt.show()
print "Done." if args.plot or args.save_plots != "": print "Plotting/saving plots." fname = "" fname_no_ext = "" fext = ".png" if args.save_plots != "": fname, fext = os.path.splitext(args.save_plots) fname_no_ext = fname + "_no_ext" print fname, fext plt.figure() print "Drawing leaf." plot.draw_leaf(leaf, fname=fname, fext=fext, dpi=600) plt.figure() print "Drawing hierarchical trees." plot.draw_tree(marked_tree, pos=tree_pos, fname=fname, fext=fext) plt.figure() if args.tree_heights: pos = tree_pos_h else: pos = tree_pos plot.draw_tree(marked_tree_no_ext, pos=pos, fname=fname_no_ext, fext=fext) plt.figure()