I ran the following script:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edge(1, 1, weight=2)
G.add_edge(1, 3, weight=2)
G.add_edge(1, 4, weight=1)
G.add_edge(1, 5, weight=5)
G.add_edge(2, 3, weight=3)
G.add_edge(2, 4, weight=2)
G.add_edge(3, 5, weight=4)
d = G.degree(1)
print G.edge[1]
print "Degree of node 1:", \
G.degree(1)
print "Weighted degree of node 1:", \
G.degree(1, weight='weight')
nx.draw(G)
plt.show()
The output is:
{1: {'weight': 2}, 3: {'weight': 2}, 4: {'weight': 1}, 5: {'weight': 5}}
Weighted degree: 5
Weighted degree: 12
And the drawing is like this:
What confused me is:
Since there are 4 nodes adjacent to the node 1 (including itself), why the degree is 5?
Since the total weight of the adjacent edges of node 1 is 10 (2+2+1+5), why the degree method produced 12?
Thanks