This is a package for analyzing the ' graph ' structure, because I only use the superficial visualization function, so this introduction will be a scratch on its use.
Solve matplotlib Chinese font missing problem,
From Pylab import mplmpl.rcparams[' font.sans-serif '] = [' Fangsong '] # Specify default font mpl.rcparams[' Axes.unicode_minus '] = False # Fix save image is minus sign '-' Display as block problem
Read in the data,
Import pandas as Pdimport networkx as Nxdata = pd.read_csv (U ' C:\Projects\python3_5\Gephi\\17 Grade Master tutor case. csv ')
Since the edge input format of the graph is in the form of (node 1, Node 2), we need to tidy up the data format,
edges = [Edge for edge in Zip (data[data.columns[0]],data[' unnamed:2 ')]edges.extend ([Edge to edge in Zip (Data[data.colu mns[0]],data[' Unnamed:3 ')] edges.extend ([Edge for Edge in Zip (data[data.columns[5]],data[' unnamed:7 '])]) Edges.extend ([Edge for Edge in Zip (data[data.columns[5]],data[' unnamed:8 ')]) edges = PD. DataFrame (edges,columns=[' mentor ', ' student ']). Dropna (how= ' any ')
Drawing, which takes the form of adding an edge to a graph object, or adding node and so on,
The actual experience is abnormal freedom, there is no type limit node ability, that is, you can put numbers, characters, other formats of objects and even another graph as a node, of course, this is not very meaningful in visualization, But the biggest function of Networkx package is actually graph analysis rather than visualization (actually visualization is an auxiliary function), I know not much, also can only help clap clap to call applause (escape ~ ~
G = NX. Graph () G.add_edges_from ([Edge for Edge in Zip (edges[' tutor '],edges[' student ')]) Nx.draw (g, # pos = Nx.random_layout (g), # pos = Nx.spring_layout (g), # pos = Nx.shell_layout (g), pos = nx.circular_layout (g), Node_color = ' R ', # edge_color = ' B ', with_labels = True, font_size =20, node_size =1000, alpha=0.3)
Because of the privacy, the figure here I canceled the label, but the actual effect is so, not too much.
Common methods of "Networkx"