Hi,
I copy pasted the code from the link you sent me and change to the following code
#! /usr/bin/env python
from graph_tool.all
import *
from numpy.random
import *
from numpy.linalg
import norm
import sys, os, os.path
seed(42)
seed_rng(42)
from gi.repository
import Gtk, Gdk, GdkPixbuf, GObject, GLib
g = Graph()
step = 0.005# move step
K = 0.5# preferred edge length
pos = sfdp_layout(g, K = K)# initial layout positions
win = GraphWindow(g, pos, geometry = (500, 400))
edges = [(1, 2), (3, 4), (3, 2), (3, 5), (3, 6), (2, 5)]
count = 0
def update_state():
global count
sfdp_layout(g, pos = pos, K = K, init_step = step, max_iter = 1)
# my code
for each in edges:
g.add_edge(each[0], each[1])
if count > 0 and count % 1000 == 0:
win.graph.fit_to_window(ink = True)
count += 1
win.graph.regenerate_surface()
win.graph.queue_draw()
return True
cid = GLib.idle_add(update_state)
win.connect("delete_event", Gtk.main_quit)
win.show_all()
Gtk.main()
This doesn't seem to work I get RuntimeError: invalid matrix (not invertible)
Any idea? it looks to me this one line g = random_graph(150, lambda: 1 + poisson(5), directed=False)
makes a difference? But I want to create my own graph like the code above.
Also what does idle_add do? it calls update whenever it is idle? which means it redraws whenever it is idle?
Thanks!