def drawGraphFromSM2(SM, names, outFile, Cut):
graph = pydot.Dot(graph_type='graph')
# THRESHOLD SM:
nonZeroMean = np.mean(SM[SM.nonzero()])
if Cut:
T = 5.0 * nonZeroMean
else:
T = 0.0;
for i in range(SM.shape[0]):
for j in range(SM.shape[0]):
if SM[i,j] <= T:
SM[i,j] = 0.0
else:
SM[i,j] = 1.0
numOfConnections = sum(SM, axis = 0)
#fig = plt.figure(1)
#plot1 = plt.imshow(SM, origin='upper', cmap=cm.gray, interpolation='nearest')
#plt.show()
numOfConnections = 9*numOfConnections / max(numOfConnections)
for i,f in enumerate(names):
if sum(SM[i,:])>0:
fillColorCurrent = "{0:d}".format(int(ceil(numOfConnections[i])))
# NOTE: SEE http://www.graphviz.org/doc/info/colors.html for color schemes
node = pydot.Node(f, style="filled", fontsize="8", shape="egg", fillcolor=fillColorCurrent, colorscheme = "reds9")
graph.add_node(node)
for i in range(len(names)):
for j in range(len(names)):
if i<j:
if SM[i][j] > 0:
#gr.add_edge((names[i], names[j]))
edge = pydot.Edge(names[i], names[j])
graph.add_edge(edge)
graph.write_png(outFile)
textFeatureExtraction.py 文件源码
python
阅读 32
收藏 0
点赞 0
评论 0
评论列表
文章目录