In [1]:
%matplotlib inline

In [2]:
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.cm as cm
import networkx as nx

import polyhedra as poly
import bga_4_0 as bga

bga = reload(bga)

In [3]:
from matplotlib import rc
rc('font', **{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)

my_figsize = (12,5)
my_dpi = 200

In [4]:
poly_name = "octahedron"

In [5]:
verts, face_inds, cents = getattr(poly, poly_name)()
V, E, F, S, species, f_types, adj_list, dual = bga.get_poly(poly_name)
ints, ids, paths, shell_int, shell_paths, edges, shell_edge, degens = bga.get_bg_ss(poly_name, get_degens=True)
Ss, Ts = bga.get_degeneracies(ints, edges, adj_list)

In [6]:
for k, e in enumerate(edges):
    print e[0], e[1], degens[k]


0 1 8
1 2 3
2 3 4
3 4 1
3 5 1
3 6 1
3 7 1
4 8 3
5 8 2
5 9 2
6 8 4
7 8 2
7 9 2
8 10 2
8 11 1
9 10 1
9 11 1
9 12 1
10 13 2
11 13 2
12 13 2
13 14 1

In [7]:
# extract nodes from graph
nodes = set([n1 for n1, n2 in edges[1:]] + [n2 for n1, n2 in edges[1:]])

# create networkx graph
#G=nx.DiGraph()
G=nx.Graph()

# add nodes
for node in nodes:
    G.add_node(node)

# add edges
for edge in edges[1:]:
    G.add_edge(edge[0], edge[1])

# draw graph
pos = nx.shell_layout(G)
#nx.draw(G, pos)

In [8]:
nx.draw(G, pos)



In [9]:
pos = {1: np.array([ 1.,  0.5]), 
       2: np.array([ 2.,  0.5]), 
       3: np.array([ 3.,  0.5]), 
       4: np.array([ 4.,  0.8]), 
       5: np.array([ 4.,  0.6]), 
       6: np.array([ 4.,  0.4]), 
       7: np.array([ 4.,  0.2]), 
       8: np.array([ 5.,  2.0/3.0]), 
       9: np.array([ 5.,  1.0/3.0]), 
       10: np.array([ 6.,  0.75]), 
       11: np.array([ 6.,  0.5]), 
       12: np.array([ 6.,  0.25]),
       13: np.array([ 7.,  0.5]), 
       14: np.array([ 8.,  0.5])}

In [10]:
pos_arr = np.array([[ 1.,  0.5], 
                    [ 2.,  0.5],
                    [ 3.,  0.5],
                    [ 4.,  0.8],
                    [ 4.,  0.6],
                    [ 4.,  0.4],
                    [ 4.,  0.2],
                    [ 5.,  2.0/3.0],
                    [ 5.,  1.0/3.0],
                    [ 6.,  0.75],
                    [ 6.,  0.5],
                    [ 6.,  0.25],
                    [ 7.,  0.5], 
                    [ 8.,  0.5]])

#node_scale = 0.1
#pos_arr[:,1] -= 0.5
#pos_arr[:,1] *= node_scale
#pos_arr[:,1] += 0.5

In [11]:
pos = {k+1: pos_arr[k,:] for k in range(len(ints)-1)}

In [27]:
node_size_scale = 50.0

node_color = 'w'
node_size = node_size_scale*pi
#edge_thickness = 1.0
edge_thickness = np.arange(len(edges))
edge_alpha = 0.5
edge_color = 'blue'
node_text_size = 12


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-27-e957728a1da4> in <module>()
      2 
      3 node_color = 'w'
----> 4 node_size = node_size_scale*pi
      5 #edge_thickness = 1.0
      6 edge_thickness = np.arange(len(edges))

NameError: name 'pi' is not defined

In [26]:
fig = plt.figure(figsize=my_figsize, dpi=my_dpi)
a = nx.draw_networkx_nodes(G, 
                       pos, 
                       node_size=node_size,
                       node_color=node_color)
b = nx.draw_networkx_edges(G,
                       pos,
                       width=edge_thickness,
                       alpha=edge_alpha,
                       edge_color=edge_color)
c = nx.draw_networkx_labels(G, 
                        pos,
                        font_size=node_text_size)



In [13]: