On 04/30/2014 01:11 PM, Николай Кинаш wrote:
Hello.
import graph_tool.all as gt import numpy as np import sys, os, os.path from gi.repository import Gtk, Gdk, GdkPixbuf, GObject
def random_attack(g): victim = g.vertex( np.random.randint( 0, g.num_vertices() ) ); g.remove_vertex( victim );
g = gt.price_network(100, directed=False); pos = gt.arf_layout(g) max_count = 50 if not os.path.exists("./frames"): os.mkdir("./frames"); win = Gtk.OffscreenWindow(); win.set_default_size(1000, 1000); win.graph = gt.GraphWidget(g, pos ); win.add(win.graph);
count = 0; def update_state(): global count; count += 1; random_attack(g); gt.arf_layout(g, pos=pos, max_iter = 1); win.graph.regenerate_surface(lazy=False); win.graph.queue_draw(); pixbuf = win.get_pixbuf(); pixbuf.savev(r'./frames/dancing%06d.png' % count, 'png', [], []); if count > max_count: sys.exit(0); return True;
cid = GObject.idle_add(update_state); win.connect("delete_event", Gtk.main_quit); win.show_all(); Gtk.main();
is there way to paint edges and vertex from largest connected component in different color?
Somthing like this: vcmap = gt.label_largest_component(g) gt.GraphWidget(g, pos, vcmap );
The GraphWidget constructor accepts the same options as graph_draw(). So, to set the color you would do: gt.GraphWidget(g, pos, vertex_fill_color=vcmap) Best, Tiago