In [1]:
    
from Goulib import notebook
import networkx as nx
from Goulib.graph import *
    
In [2]:
    
g=nx.gn_graph(20)
nx.draw_networkx(g)
    
    
In [3]:
    
draw_networkx(g, #improved version over nx.draw_networkx
labels=True, # by default they're off
)
    
    Out[3]:
    
In [4]:
    
geo=nx.geographical_threshold_graph(50,25)
geo # NetworkX Graphs do not render in Notebooks...
    
    Out[4]:
In [5]:
    
geo=GeoGraph(geo)
geo # GeoGraphs do !
    
    
    Out[5]:
In [6]:
    
# it's easy to make GeoGraphs look nice
def edge_color(data): # simply define a function that maps edge data to a color
    return plt.get_cmap('Blues')(data['length']/.25)       
geo.render(edge_color=edge_color, node_size=50) #this will set geo.render_args ...
geo #... so here we display them :-)
    
    Out[6]:
In [7]:
    
d=to_drawing(geo) # graphs can also be converted or added to a Goulib.Drawing
from Goulib.geom import Circle
c=Circle((0.5,0.5),0.5)
c.color='red'
d.append(c)
    
    Out[7]:
In [8]:
    
nodes=points_on_sphere(120)
sphere=GeoGraph(nodes=nodes) #GeoGraphs can also be built from n-dim points only
sphere.render(edge_color=edge_color, node_size=50) #this will set geo.render_args ...
sphere
    
    Out[8]:
In [10]:
    
delauney_triangulation(sphere,'Qz') #creates a new GeoGraph from Delauney triangulation of a GeoGraph's nodes
    
    Out[10]:
In [ ]: