networkx - How to add a simple "colorbar" to a network-graph plot in python? -


I was thinking how I can easily add a colorbar to my plot, I have to follow the code, which Reads the GML file and graphs the file. I have a set of numbers to designate the edges as their colors and I just want to see a colorbar next to the plot so that I can analyze the colors. When I add plt.colorbar (g) then gives me an error How can I actually add a color palette without going through all the processes of creating a color palette?

H = nx.read_gml ('./ network1.gml') EAM = EigenVectorCentrality (EAMatrix); X = []; [0]: X.Append (im [0]) for EM in EAM; 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 ('equals') plt.colorbar (g); Plt.show ()

And here is the Nerwork1.gml file:

  Article [node [id1] node [id2] node [id 3 ] Node [ID4] node [ID5] node [ID6] node [ID7] node [ID8] node [ID 9] node [ID10] node [ID11] edge [Source 1 goal 2] edge [ Source 1 Goal 2] Side [Source 1 Goal 3] Side [Source 1 Goal 4] Side [Source 1 Goal 5] Edge [Source 2 Goal 3] Edge [Source 2 Goal 4] Edge [Source 2 Goal 5] Edge [Source 3 goals 4] edge [source 3 target 5] edge Source 4 Goal 5] Advantage [source 6 Goal 7] edge [source 6 goal 8] edge [source 6 goal 9] edge [source 6 goal 10] edge [source 7 goal 8] edge [source 7 target 9] edge [source 7 goals 10] edge [source 8 target 9] edge [source 8 goal 10] edge [source 9 goal 10] edge [source 5 goal 6] edge [source 5 goal 11] edge [source 6 goal 11]]   

Since I had no data available to you, I would get from the networks homepage Was used. But it should be trivial for you to use in your code.

  import matlotlib.pyplot as plt import network x nx g = nx.star_graph (20) pos = nx.spring_layout (g) color = range (20) cmap = plt.cm .blues vmin = min (color) vmax = max (color) nx.draw (G, pos, node_color = '# A0CBE2', edgecolor = color, width = 4, maximize = Cmap, with_labels = False, vmin = vmin, vmax = Vmax) sm = plt.cm.ScalarMappable (equals = semi, value = PLT. (Vmin = vmin, vmax = vmax) sm._A = [] plt.colorbar (sm) plt.show ()  

So, it does the trick but I agree, it is a little sad that nx.draw just any returns.


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -