Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
SELECT DISTINCT ?parent ?node
FROM
WHERE {
?node skos:broader ?parent
} ORDER BY ?parent
""")
resultsEdges = sparql.query().convert()
for y in resultsEdges["results"]["bindings"]:
g1.add_edge(("/".join(y["parent"]["value"].split("/")[5:]), "/".join(y["node"]["value"].split("/")[5:])))
# Draw as PNG
# print "Writing plot..."
dot = write(g1)
G = pgv.AGraph(dot)
G.layout(prog='dot')
G.draw('../output/foo.png')
print G.string()
# gvv = gv.readstring(dot)
def visualize(data, processes, root):
G = pgv.AGraph(directed=False, strict=False)
G.node_attr['shape']='box'
for pid, p in processes.iteritems():
if pid == root.pid:
G.add_node(p.name() + "\n" + str(pid), color="black")
else:
G.add_node(p.name() + "\n" + str(pid), color="green")
#node = G.get_node(p.name() + "\n" + str(pid))
for el in data:
if el["dst_pid"] != 0:
G.add_edge(el["src_prog"] + "\n" + str(el["src_pid"]), el["dst_prog"] + "\n" + str(el["dst_pid"]), color="blue", len="1.5")
else:
G.add_node(el["dst_prog"] + "\nExternal", color="red")
G.add_edge(el["src_prog"] + "\n" + str(el["src_pid"]), el["dst_prog"] + "\nExternal", color="red", len="1.5")
def build_fat_graph():
"""Build http://www.graphviz.org/content/twopi2"""
G = pgv.AGraph('graph_coloring_z3_example_fat_graph.gv')
return (G, 'twopi2_fat_graph', 'twopi')
def orBox(bioNumber):
with open('orBox{0}.dump'.format(bioNumber),'rb') as f:
boxes = pickle.load(f)
fileName = 'image'
graph = pgv.AGraph(directed=False,concentrate=True)
print boxes[0]
for element in boxes[0]:
graph.add_node(element,shape='diamond',color='pink',style='filled')
s = set()
edges = set()
rootEdges = set()
for component in boxes[0][element]:
s.add('{0}'.format(component[0]))
s.add('{0}'.format(component[1]))
#if boxes[0][element][component]:
# edges.add(('{0}-{1}'.format(element,component[0]),'{0}-{1}'.format(element,component[1])))
rootEdges.add((element,'{0}-{1}'.format(element,component[0])))
rootEdges.add((element,'{0}-{1}'.format(element,component[1])))
for item in s:
graph.add_node('{0}-{1}'.format(element,item),label=item)
def build_peternson_3_coloring_graph():
"""Build http://en.wikipedia.org/wiki/File:Petersen_graph_3-coloring.svg"""
G = pgv.AGraph()
G.node_attr['style'] = 'filled'
# Hum, the attribute 'directed' (in AGraph constructor) doesn't seem to work, so that's my workaround.
G.edge_attr['dir'] = 'none'
edges = [
(0, 2), (0, 1), (0, 5), (0, 4), (1, 6), (1, 7),
(2, 3), (2, 8), (3, 4), (3, 7), (4, 5), (4, 6),
(5, 9), (6, 8), (7, 9), (8, 9), (9, 3)
]
for i in range(10):
G.add_node(i)
for src, dst in edges:
G.add_edge(src, dst)
Notes
-----
If N has an dict N.graph_attr an attempt will be made first
to copy properties attached to the graph (see from_agraph)
and then updated with the calling arguments if any.
"""
try:
import pygraphviz
except ImportError:
raise ImportError('requires pygraphviz ',
'http://pygraphviz.github.io/')
directed = N.is_directed()
strict = nx.number_of_selfloops(N) == 0 and not N.is_multigraph()
A = pygraphviz.AGraph(name=N.name, strict=strict, directed=directed)
# default graph attributes
A.graph_attr.update(N.graph.get('graph', {}))
A.node_attr.update(N.graph.get('node', {}))
A.edge_attr.update(N.graph.get('edge', {}))
A.graph_attr.update((k, v) for k, v in N.graph.items()
if k not in ('graph', 'node', 'edge'))
# add nodes
for n, nodedata in N.nodes(data=True):
A.add_node(n)
if nodedata is not None:
a = A.get_node(n)
a.attr.update({k: str(v) for k, v in nodedata.items()})
def __init_graph(self, resdir):
graphdir = os.path.abspath(os.path.join(resdir, os.pardir))
self.svgfile = os.path.join(graphdir, "graph.svg")
self.graph = pygraphviz.AGraph(strict = False,
directed = True,
rankdir = 'LR')
def request_relayout(self):
if self.graph is None:
return
# remove all edges
for p in self._edge_paths:
self.scene.removeItem(p)
# remove all nodes
self.remove_all_children()
self._edge_paths = []
g = pygraphviz.AGraph(directed=True)
g.graph_attr['nodesep'] = 100
g.graph_attr['ranksep'] = 50
g.node_attr['shape'] = 'rect'
for node in self.graph.nodes_iter():
scene_proxy = self._proxy(node)
size = node.size()
width, height = size.width(), size.height()
scene_proxy.setGeometry(QRectF(0.0, 0.0, width, height))
g.add_node(node, width=width, height=height)
for from_, to in self.graph.edges_iter():
g.add_edge(from_, to)
g.layout(prog='dot')
def draw_BN(g, path):
graph = pgv.AGraph(directed=True, strict=True, fontname='Helvetica', arrowtype='open')
label_dict = dict(zip(range(2, 10), 'ASTLBEXD'))
pos_dict = dict(zip(range(2, 10), ['0, 3!', '2.75, 3!', '0, 2!', '2, 2!', '3.5, 1!', '1.5, 1!', '1.5, 0!', '3.5, 0!']))
def add_node(graph, node_id, label, shape='circle', style='filled'):
if label in {0, 1}:
return
else:
label, pos = label_dict[label], pos_dict[label]
graph.add_node(
node_id, label=label, color='black', fillcolor='white',
shape=shape, style=style, pos=pos, fontsize=27,
)
return
if g is None:
graph.add_node(