I was wondering how can I simply add a colorbar to my plot. I have to following code, which plots a graph by reading a gml file. I have a set of numbers to assign to the edges as their colors and I just want to see a colorbar right next to the plot so I can analyze the colors. When I add the plt.colorbar(g)
it gives me error. How can I add a colorbar without going through all the process of actually building the colorbar?
H = nx.read_gml('./network1.gml')
EAM = EigenVectorCentrality( EAMatrix );
x = [];
for eam in EAM[0]:
x.append(eam[0]);
degs = H.degree().values();
plt.clf()
g = nx.draw(H, with_labels=0, edge_color=x, node_size=70, font_size=9, width=1)
plt.axis('equal')
plt.colorbar(g);
plt.show()
And here is the Nerwork1.gml file:
graph
[
node
[
id 1
]
node
[
id 2
]
node
[
id 3
]
node
[
id 4
]
node
[
id 5
]
node
[
id 6
]
node
[
id 7
]
node
[
id 8
]
node
[
id 9
]
node
[
id 10
]
node
[
id 11
]
edge
[
source 1
target 2
]
edge
[
source 1
target 2
]
edge
[
source 1
target 3
]
edge
[
source 1
target 4
]
edge
[
source 1
target 5
]
edge
[
source 2
target 3
]
edge
[
source 2
target 4
]
edge
[
source 2
target 5
]
edge
[
source 3
target 4
]
edge
[
source 3
target 5
]
edge
[
source 4
target 5
]
edge
[
source 6
target 7
]
edge
[
source 6
target 8
]
edge
[
source 6
target 9
]
edge
[
source 6
target 10
]
edge
[
source 7
target 8
]
edge
[
source 7
target 9
]
edge
[
source 7
target 10
]
edge
[
source 8
target 9
]
edge
[
source 8
target 10
]
edge
[
source 9
target 10
]
edge
[
source 5
target 6
]
edge
[
source 5
target 11
]
edge
[
source 6
target 11
]
]
nx.draw
returnsNone
, that is whyplt.colorbar
fails. Also: could you post the filenetwork1.gml
somewhere?