#!/usr/bin/env python # coding: utf-8 # # [Goulib](../notebook.ipynb).graph # efficient Euclidian Graphs for [NetworkX](http://networkx.github.io/) and related algorithms # 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 ) # In[4]: geo=nx.geographical_threshold_graph(50,25) geo # NetworkX Graphs do not render in Notebooks... # In[5]: geo=GeoGraph(geo) geo # GeoGraphs do ! # 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 :-) # 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) # 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 # In[10]: delauney_triangulation(sphere,'Qz') #creates a new GeoGraph from Delauney triangulation of a GeoGraph's nodes # In[ ]: