Пример #1
0
 def test_graph_from_adjacency_matrix(self):
     g = pydot.graph_from_adjacency_matrix(
         [[0, 1, 0], [1, 0, 0], [0, 1, 1]], directed=True)
     s = ' '.join(g.to_string().split())
     self.assertEqual(s, 'digraph G { 1 -> 2; 2 -> 1; 3 -> 2; 3 -> 3; }')
     g = pydot.graph_from_adjacency_matrix(
         [[0, 1, 0], [1, 0, 0], [0, 0, 1]], directed=False)
     s = ' '.join(g.to_string().split())
     self.assertEqual(s, 'graph G { 1 -- 2; 3 -- 3; }')
Пример #2
0
import os.path

# Set up a list of valid files
files = list()
for fileName in sys.argv[1:len(sys.argv)]:
	if os.path.exists(fileName) and os.path.isfile(fileName):
		files.append(fileName)

# Go through and generate a report for each file
for fileName in files:
	infile = open(fileName, "r")
	numberOfRows = int(infile.readline())
	
	matrix = list()
	# Iteartively build the adjacency matrix for the graph
	for x in range(0,numberOfRows):
		line = infile.readline()
		stringValues = line.split()
		values = list()
		for val in stringValues:
			values.append(int(val))
		#print values
		matrix.append(values)
    
    # Use the adjacency matrix to construct the graph
	graph = pydot.graph_from_adjacency_matrix(matrix, node_prefix='v', directed=False)

    # Just write the graph now
	graph.write_png(fileName + '.png')

# Done
Пример #3
0
import pydot 

filename = "example_simple_graph3.pdf"
render_engine= ['dot', 'circo','neato'][2]
G = pydot.graph_from_adjacency_matrix([])

'''
A = [[0,1,1],[1,1,1],[1,1,0]]
G = pydot.graph_from_adjacency_matrix([])
for i in range(len(A)):
    for j in range(len(A)):
        if i>=j and A[i][j]:
            edge = pydot.Edge(str(i),str(j))
            edge.set_weight('.5')
            G.add_edge(edge)
'''
E = [[0,24],[1,24]]
for edge in E:
    edge = pydot.Edge(str(edge[0]),str(edge[1]))
    G.add_edge(edge)

#help(pydot.Edge)
edge = pydot.Edge(str(24),str(3),label="x2",penwidth='2.0')
G.add_edge(edge)

names = map(str,range(0,5))
names = ['0','1','24','3']

for x in names: 
    node = pydot.Node(x,shape='circle')
    node.set_style('filled')
Пример #4
0
#!/usr/bin/env python
import pydot

mat = [[0,2,4,1],
       [1,0,1,1],
       [5,0,0,1],
       [1,0,1,0]]
 
#graph = pydot.Dot('cluster_graph', graph_type='graph') 
#subg = pydot.Subgraph.graph_from_adjaceny_matrix(amat,node_prefix="C")
#graph.add_subgraph(subg)
graph = pydot.graph_from_adjacency_matrix(mat)
graph.write("./graph.ps",prog="dot",format="ps")
import pydot

filename = "example_simple_graph.pdf"
render_engine = ['dot', 'circo', 'neato'][2]
G = pydot.graph_from_adjacency_matrix([])
'''
A = [[0,1,1],[1,1,1],[1,1,0]]
G = pydot.graph_from_adjacency_matrix([])
for i in range(len(A)):
    for j in range(len(A)):
        if i>=j and A[i][j]:
            edge = pydot.Edge(str(i),str(j))
            edge.set_weight('.5')
            G.add_edge(edge)
'''
E = [[0, 2], [1, 2], [2, 3], [3, 4], [2, 4]]
for edge in E:
    edge = pydot.Edge(str(edge[0]), str(edge[1]))
    edge.set_weight('.5')
    G.add_edge(edge)

names = map(str, range(0, 5))

for x in names:
    node = pydot.Node(x, shape='circle')
    node.set_style('filled')
    node.set_fillcolor('white')

    if x in ['0', '1']: node.set_fillcolor('plum')
    #if x in ['3']: node.set_fillcolor('tan')
    if x in ['4', '3']: node.set_fillcolor('lightskyblue')