summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Schult <dschult@colgate.edu>2015-10-04 00:46:24 -0400
committerDan Schult <dschult@colgate.edu>2015-10-04 00:46:24 -0400
commit43a5099763053d53d4d5daf7d593b0ee836fc3a4 (patch)
treeae0a60842c27b13380a20f55891c7bdde521329d
parent578aff0b10bef648ef0a770b78229cfb11e3a763 (diff)
parentcab7b9b449901dd01d72d11c56a78708547e28f6 (diff)
downloadnetworkx-43a5099763053d53d4d5daf7d593b0ee836fc3a4.tar.gz
Merge pull request #1794 from dschult/fix-examples
Update examples for iterator edges and nodes methods
-rw-r--r--examples/3d_drawing/mayavi2_spring.py10
-rw-r--r--examples/advanced/heavy_metal_umlaut.py2
-rw-r--r--examples/drawing/degree_histogram.py2
-rw-r--r--examples/drawing/ego_graph.py2
-rw-r--r--examples/drawing/random_geometric_graph.py2
-rw-r--r--examples/drawing/sampson.py2
-rw-r--r--examples/graph/degree_sequence.py2
-rw-r--r--examples/pygraphviz/pygraphviz_attributes.py2
-rw-r--r--examples/subclass/antigraph.py6
-rw-r--r--examples/subclass/printgraph.py10
10 files changed, 20 insertions, 20 deletions
diff --git a/examples/3d_drawing/mayavi2_spring.py b/examples/3d_drawing/mayavi2_spring.py
index b9eda22b..79141c06 100644
--- a/examples/3d_drawing/mayavi2_spring.py
+++ b/examples/3d_drawing/mayavi2_spring.py
@@ -15,21 +15,21 @@ G=nx.convert_node_labels_to_integers(H)
# 3d spring layout
pos=nx.spring_layout(G,dim=3)
# numpy array of x,y,z positions in sorted node order
-xyz=np.array([pos[v] for v in sorted(G)])
+xyz=np.array([pos[v] for v in sorted(G)])
# scalar colors
-scalars=np.array(G.nodes())+5
+scalars=np.array(list(G.nodes()))+5
mlab.figure(1, bgcolor=(0, 0, 0))
mlab.clf()
-pts = mlab.points3d(xyz[:,0], xyz[:,1], xyz[:,2],
+pts = mlab.points3d(xyz[:,0], xyz[:,1], xyz[:,2],
scalars,
scale_factor=0.1,
scale_mode='none',
colormap='Blues',
- resolution=20)
+ resolution=20)
-pts.mlab_source.dataset.lines = np.array(G.edges())
+pts.mlab_source.dataset.lines = np.array(list(G.edges()))
tube = mlab.pipeline.tube(pts, tube_radius=0.01)
mlab.pipeline.surface(tube, color=(0.8, 0.8, 0.8))
diff --git a/examples/advanced/heavy_metal_umlaut.py b/examples/advanced/heavy_metal_umlaut.py
index 1f45cf4f..e741fddf 100644
--- a/examples/advanced/heavy_metal_umlaut.py
+++ b/examples/advanced/heavy_metal_umlaut.py
@@ -64,7 +64,7 @@ for n in G.nodes():
if n not in H:
print(False)
-print(G.nodes())
+print(list(G.nodes()))
try:
pos=NX.spring_layout(G)
diff --git a/examples/drawing/degree_histogram.py b/examples/drawing/degree_histogram.py
index 0827c1f5..f89dd684 100644
--- a/examples/drawing/degree_histogram.py
+++ b/examples/drawing/degree_histogram.py
@@ -8,7 +8,7 @@ import networkx as nx
import matplotlib.pyplot as plt
G = nx.gnp_random_graph(100,0.02)
-degree_sequence=sorted(nx.degree(G).values(),reverse=True) # degree sequence
+degree_sequence=sorted([d for n,d in G.degree()],reverse=True) # degree sequence
#print "Degree sequence", degree_sequence
dmax=max(degree_sequence)
diff --git a/examples/drawing/ego_graph.py b/examples/drawing/ego_graph.py
index 81305e61..00c47fbe 100644
--- a/examples/drawing/ego_graph.py
+++ b/examples/drawing/ego_graph.py
@@ -18,7 +18,7 @@ if __name__ == '__main__':
G=nx.generators.barabasi_albert_graph(n,m)
# find node with largest degree
node_and_degree=G.degree()
- (largest_hub,degree)=sorted(node_and_degree.items(),key=itemgetter(1))[-1]
+ (largest_hub,degree)=sorted(node_and_degree,key=itemgetter(1))[-1]
# Create ego graph of main hub
hub_ego=nx.ego_graph(G,largest_hub)
# Draw graph
diff --git a/examples/drawing/random_geometric_graph.py b/examples/drawing/random_geometric_graph.py
index d39fec6f..78c480e0 100644
--- a/examples/drawing/random_geometric_graph.py
+++ b/examples/drawing/random_geometric_graph.py
@@ -16,7 +16,7 @@ for n in pos:
dmin=d
# color by path length from node near center
-p=nx.single_source_shortest_path_length(G,ncenter)
+p = dict(nx.single_source_shortest_path_length(G, ncenter))
plt.figure(figsize=(8,8))
nx.draw_networkx_edges(G,pos,nodelist=[ncenter],alpha=0.4)
diff --git a/examples/drawing/sampson.py b/examples/drawing/sampson.py
index 0655102b..914e5644 100644
--- a/examples/drawing/sampson.py
+++ b/examples/drawing/sampson.py
@@ -38,7 +38,7 @@ plt.title('samplike3')
nx.draw(G3,pos,node_size=50,with_labels=False)
plt.subplot(224)
plt.title('samplike1,2,3')
-nx.draw(G3,pos,edgelist=G3.edges(),node_size=50,with_labels=False)
+nx.draw(G3, pos, edgelist=list(G3.edges()), node_size=50, with_labels=False)
nx.draw_networkx_edges(G1,pos,alpha=0.25)
nx.draw_networkx_edges(G2,pos,alpha=0.25)
plt.savefig("sampson.png") # save as png
diff --git a/examples/graph/degree_sequence.py b/examples/graph/degree_sequence.py
index 6acc394e..b750dd41 100644
--- a/examples/graph/degree_sequence.py
+++ b/examples/graph/degree_sequence.py
@@ -20,7 +20,7 @@ print(is_valid_degree_sequence(z))
print("Configuration model")
G=configuration_model(z) # configuration model
-degree_sequence=list(degree(G).values()) # degree sequence
+degree_sequence = [d for n,d in G.degree()] # degree sequence
print("Degree sequence %s" % degree_sequence)
print("Degree histogram")
hist={}
diff --git a/examples/pygraphviz/pygraphviz_attributes.py b/examples/pygraphviz/pygraphviz_attributes.py
index 19110ca4..d7ab0696 100644
--- a/examples/pygraphviz/pygraphviz_attributes.py
+++ b/examples/pygraphviz/pygraphviz_attributes.py
@@ -36,7 +36,7 @@ A.write('k5_attributes.dot')
# default attributes as dictionary data
X=nx.from_agraph(A)
print("edges")
-print(X.edges(data=True))
+print(list(X.edges(data=True)))
print("default graph attributes")
print(X.graph)
print("node node attributes")
diff --git a/examples/subclass/antigraph.py b/examples/subclass/antigraph.py
index 3f900696..31c5fc2a 100644
--- a/examples/subclass/antigraph.py
+++ b/examples/subclass/antigraph.py
@@ -168,7 +168,7 @@ if __name__ == '__main__':
node = list(G.nodes())[0]
nodes = list(G.nodes())[1:4]
assert G.degree(node) == A.degree(node)
- assert sum(G.degree().values()) == sum(A.degree().values())
+ assert sum(d for n,d in G.degree()) == sum(d for n,d in A.degree())
# AntiGraph is a ThinGraph, so all the weights are 1
- assert sum(A.degree().values()) == sum(A.degree(weight='weight').values())
- assert sum(G.degree(nodes).values()) == sum(A.degree(nodes).values())
+ assert sum(d for n,d in A.degree()) == sum(d for n,d in A.degree(weight='weight'))
+ assert sum(d for n,d in G.degree(nodes)) == sum(d for n,d in A.degree(nodes))
diff --git a/examples/subclass/printgraph.py b/examples/subclass/printgraph.py
index 5845a122..9f11d52d 100644
--- a/examples/subclass/printgraph.py
+++ b/examples/subclass/printgraph.py
@@ -117,12 +117,12 @@ if __name__=='__main__':
G.remove_nodes_from('ar')
print(G.nodes(data=True))
G.add_edge(0,1,weight=10)
- print(G.edges(data=True))
+ print(list(G.edges(data=True)))
G.remove_edge(0,1)
G.add_edges_from(list(zip(list(range(0o3)),list(range(1,4)))),weight=10)
- print(G.edges(data=True))
+ print(list(G.edges(data=True)))
G.remove_edges_from(list(zip(list(range(0o3)),list(range(1,4)))))
- print(G.edges(data=True))
+ print(list(G.edges(data=True)))
G=PrintGraph()
@@ -130,6 +130,6 @@ if __name__=='__main__':
print("subgraph")
H1=G.subgraph(list(range(4)),copy=False)
H2=G.subgraph(list(range(4)),copy=False)
- print(H1.edges())
- print(H2.edges())
+ print(list(H1.edges()))
+ print(list(H2.edges()))