本文整理汇总了Python中networkx.graphviz_layout方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.graphviz_layout方法的具体用法?Python networkx.graphviz_layout怎么用?Python networkx.graphviz_layout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.graphviz_layout方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: viz_factor_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import graphviz_layout [as 别名]
def viz_factor_graph(gm):
"""
ut.qtensure()
gm = build_factor_graph(G, nodes, edges , n_annots, n_names, lookup_annot_idx,
use_unaries=True, edge_probs=None, operator='multiplier')
"""
ut.qtensure()
import networkx
from networkx.drawing.nx_agraph import graphviz_layout
networkx.graphviz_layout = graphviz_layout
opengm.visualizeGm(gm, show=False, layout="neato", plotUnaries=True,
iterations=1000, plotFunctions=True,
plotNonShared=False, relNodeSize=1.0)
_ = pt.show_nx(gm.G) # NOQA
# import utool
# utool.embed()
# infr = opengm.inference.Bruteforce
# infr = opengm.inference.Bruteforce(gm, accumulator='maximizer')
# # infr = opengm.inference.Bruteforce(gm, accumulator='maximizer')
# # infr = opengm.inference.Bruteforce(gm, accumulator='integrator')
# infr.infer()
# print(infr.arg())
# print(infr.value())
示例2: draw_adjacency_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import graphviz_layout [as 别名]
def draw_adjacency_graph(adjacency_matrix,
node_color=None,
size=10,
layout='graphviz',
prog='neato',
node_size=80,
colormap='autumn'):
"""draw_adjacency_graph."""
graph = nx.from_scipy_sparse_matrix(adjacency_matrix)
plt.figure(figsize=(size, size))
plt.grid(False)
plt.axis('off')
if layout == 'graphviz':
pos = nx.graphviz_layout(graph, prog=prog)
else:
pos = nx.spring_layout(graph)
if len(node_color) == 0:
node_color = 'gray'
nx.draw_networkx_nodes(graph, pos,
node_color=node_color,
alpha=0.6,
node_size=node_size,
cmap=plt.get_cmap(colormap))
nx.draw_networkx_edges(graph, pos, alpha=0.5)
plt.show()
# draw a whole set of graphs::
示例3: draw_junction_tree
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import graphviz_layout [as 别名]
def draw_junction_tree(model, fnum=None, **kwargs):
import plottool_ibeis as pt
fnum = pt.ensure_fnum(fnum)
pt.figure(fnum=fnum)
ax = pt.gca()
from pgmpy.models import JunctionTree
if not isinstance(model, JunctionTree):
netx_graph = model.to_junction_tree()
else:
netx_graph = model
# prettify nodes
def fixtupkeys(dict_):
return {
', '.join(k) if isinstance(k, tuple) else k: fixtupkeys(v)
for k, v in dict_.items()
}
n = fixtupkeys(netx_graph.nodes)
e = fixtupkeys(netx_graph.edge)
a = fixtupkeys(netx_graph.adj)
netx_graph.nodes = n
netx_graph.edge = e
netx_graph.adj = a
#netx_graph = model.to_markov_model()
#pos = nx.nx_agraph.pygraphviz_layout(netx_graph)
#pos = nx.nx_agraph.graphviz_layout(netx_graph)
pos = nx.pydot_layout(netx_graph)
node_color = [pt.NEUTRAL] * len(pos)
drawkw = dict(pos=pos, ax=ax, with_labels=True, node_color=node_color,
node_size=2000)
nx.draw(netx_graph, **drawkw)
if kwargs.get('show_title', True):
pt.set_figtitle('Junction / Clique Tree / Cluster Graph')
示例4: draw
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import graphviz_layout [as 别名]
def draw(G, metrics=dict()):
import matplotlib.pyplot as plt
"""
dot - "hierarchical" or layered drawings of directed graphs. This is the default tool to use if edges have directionality.
neato - "spring model'' layouts. This is the default tool to use if the graph is not too large (about 100 nodes) and you don't know anything else about it. Neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling.
fdp - "spring model'' layouts similar to those of neato, but does this by reducing forces rather than working with energy.
sfdp - multiscale version of fdp for the layout of large graphs.
twopi - radial layouts, after Graham Wills 97. Nodes are placed on concentric circles depending their distance from a given root node.
circo - circular layout, after Six and Tollis 99, Kauffman and Wiese 02. This is suitable for certain diagrams of multiple cyclic structures, such as certain telecommunications networks.
"""
print 'layouting'
text = ''
for k, v in metrics.items():
text += '%s: %.4f\n' % (k.ljust(max(len(x) for x in metrics.keys())), v)
print text
#pos = nx.graphviz_layout(G, prog='dot', args='')
pos = nx.spring_layout(G)
plt.figure(figsize=(8, 8))
nx.draw(G, pos, node_size=20, alpha=0.5, node_color="blue", with_labels=False)
plt.text(0.02, 0.02, text, transform=plt.gca().transAxes) # , font_family='monospace')
plt.axis('equal')
outfile = 'network_graph.png'
plt.savefig(outfile)
print 'saved visualization to', outfile
plt.ion()
plt.show()
while True:
time.sleep(0.1)
示例5: _plot_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import graphviz_layout [as 别名]
def _plot_graph(graph, filename=None, node_size=500):
nx.draw_networkx(
graph,
nx.graphviz_layout(graph),
node_size=node_size)
if filename is None:
pylab.show()
else:
pylab.savefig(filename)
示例6: draw_tree_model
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import graphviz_layout [as 别名]
def draw_tree_model(model, **kwargs):
import plottool_ibeis as pt
import networkx as netx
if not ut.get_argval('--hackjunc'):
fnum = pt.ensure_fnum(None)
fig = pt.figure(fnum=fnum, doclf=True) # NOQA
ax = pt.gca()
#name_nodes = sorted(ut.list_getattr(model.ttype2_cpds[NAME_TTYPE], 'variable'))
netx_graph = model.to_markov_model()
#pos = netx.pygraphviz_layout(netx_graph)
#pos = netx.graphviz_layout(netx_graph)
#pos = get_hacked_pos(netx_graph, name_nodes, prog='neato')
pos = netx.nx_pydot.pydot_layout(netx_graph)
node_color = [pt.WHITE] * len(pos)
drawkw = dict(pos=pos, ax=ax, with_labels=True, node_color=node_color,
node_size=1100)
netx.draw(netx_graph, **drawkw)
if kwargs.get('show_title', True):
pt.set_figtitle('Markov Model')
if not ut.get_argval('--hackmarkov'):
fnum = pt.ensure_fnum(None)
fig = pt.figure(fnum=fnum, doclf=True) # NOQA
ax = pt.gca()
netx_graph = model.to_junction_tree()
# prettify nodes
def fixtupkeys(dict_):
return {
', '.join(k) if isinstance(k, tuple) else k: fixtupkeys(v)
for k, v in dict_.items()
}
# FIXME
n = fixtupkeys(netx_graph.node)
e = fixtupkeys(netx_graph.edge)
a = fixtupkeys(netx_graph.adj)
netx_graph.nodes.update(n)
netx_graph.edges.update(e)
netx_graph.adj.update(a)
#netx_graph = model.to_markov_model()
#pos = netx.pygraphviz_layout(netx_graph)
#pos = netx.graphviz_layout(netx_graph)
pos = netx.nx_pydot.pydot_layout(netx_graph)
node_color = [pt.WHITE] * len(pos)
drawkw = dict(pos=pos, ax=ax, with_labels=True, node_color=node_color,
node_size=2000)
netx.draw(netx_graph, **drawkw)
if kwargs.get('show_title', True):
pt.set_figtitle('Junction/Clique Tree / Cluster Graph')
示例7: showGraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import graphviz_layout [as 别名]
def showGraph(root, filename='test.dot'):
import matplotlib.pyplot as plt
g, good, bad, mid = makeGraph(root)
plt.figure(figsize=(10, 10), dpi=80)
nx.write_dot(g, filename)
# same layout using matplotlib with no labels
pos = nx.graphviz_layout(g, prog='dot')
nx.draw_networkx_edges(g, pos, width=1.0, alpha=1., arrows=False)
ALPHA = 1.0
colors = [(0.2, 0.8, 0.2)] * len(good)
nx.draw_networkx_nodes(g, pos,
nodelist=good,
node_color=colors,
alpha=ALPHA,
node_shape='s',
node_size=1600)
colors = [(0.9, 0.4, 0.4)] * len(bad)
nx.draw_networkx_nodes(g, pos,
nodelist=bad,
node_color=colors,
alpha=ALPHA,
node_shape='8',
node_size=1600)
colors = [(0.8, 0.8, 0.8)] * len(mid)
nx.draw_networkx_nodes(g, pos,
nodelist=mid,
node_color=colors,
node_shape='s',
alpha=ALPHA,
node_size=1600)
labels = {}
lookup = {
"NODE": "0",
"Default": "D",
"Left": "L",
"Right": "R",
"Pass": "P",
"Stop": "S",
"Wait": "W",
"Follow": "F",
"Finish": "C",
}
for name in good:
labels[name] = lookup[name.split(' ')[0]]
for name in bad:
labels[name] = lookup[name.split(' ')[0]]
for name in mid:
labels[name] = lookup[name.split(' ')[0]]
nx.draw_networkx_labels(g, pos, labels, font_size=20)
plt.axis('off')
plt.show()