本文整理汇总了Python中networkx.drawing.nx_agraph.graphviz_layout方法的典型用法代码示例。如果您正苦于以下问题:Python nx_agraph.graphviz_layout方法的具体用法?Python nx_agraph.graphviz_layout怎么用?Python nx_agraph.graphviz_layout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.drawing.nx_agraph
的用法示例。
在下文中一共展示了nx_agraph.graphviz_layout方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _layoutBlockGraph
# 需要导入模块: from networkx.drawing import nx_agraph [as 别名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 别名]
def _layoutBlockGraph(self):
# note that graphviz expects sizes in inches, so we scale them back
self._setGraphNodeSizes(1. / self.GRAPHVIZ_SCALE_FACTOR)
# dot is for directed graphs
layout = graphviz_layout(self.blockGraph, prog='dot')
layout = self._fixGraphvizLayout(layout)
for blockAddr in self.blockAddrs:
# this both updates the HTML element, and the graph node's
# x and y attributes
self._setBlockPos(blockAddr, layout[blockAddr])
# now set node sizes for edge layout algo
self._setGraphNodeSizes(scalingFactor=1.0)
layoutAlgo = _EdgeLayoutAlgo(self.blockGraph)
edgePaths = layoutAlgo.doLayout()
for b1Addr, b2Addr in self.blockGraph.edges_iter():
self._setEdgePath(b1Addr, b2Addr, edgePaths[b1Addr, b2Addr])
self._updateSceneRect(edgePaths)
示例2: draw_wstate_tree
# 需要导入模块: from networkx.drawing import nx_agraph [as 别名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 别名]
def draw_wstate_tree(svm):
import matplotlib.pyplot as plt
import networkx as nx
from networkx.drawing.nx_agraph import write_dot, graphviz_layout
G = nx.DiGraph()
pending_list = [svm.root_wstate]
while len(pending_list):
root = pending_list.pop()
for trace, children in root.trace_to_children.items():
for c in children:
G.add_edge(repr(root), repr(c), label=trace)
pending_list.append(c)
# pos = nx.spring_layout(G)
pos = graphviz_layout(G, prog='dot')
edge_labels = nx.get_edge_attributes(G, 'label')
nx.draw(G, pos)
nx.draw_networkx_edge_labels(G, pos, edge_labels, font_size=8)
nx.draw_networkx_labels(G, pos, font_size=10)
plt.show()
示例3: recalculate_positions
# 需要导入模块: from networkx.drawing import nx_agraph [as 别名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 别名]
def recalculate_positions(self, prog='sfdp', *args, **kwargs):
try:
self.positions = graphviz_layout(self._G, prog=prog, *args, **kwargs)
except ImportError:
import warnings
warnings.warn("Unable to use graphviz, please install pygraphviz. Using networkx spring layout by default")
self.positions = nx.spring_layout(self._G, *args, **kwargs)
return self.positions
示例4: main
# 需要导入模块: from networkx.drawing import nx_agraph [as 别名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 别名]
def main():
# Create a directed graph
G = nx.DiGraph()
# An example
l=[ ('a','b'),
('b','c'),
('c','d'),
('d','e'),
('e','f'),
('w','x'),
('w','t'),
('t','q'),
('q','r'),
('q','u')]
# Build up a graph
for t in l:
G.add_edge(t[0], t[1])
# Plot trees
pos = graphviz_layout(G, prog='dot')
nx.draw(G, pos, with_labels=True, arrows=False)
plt.savefig('draw_trees_with_pygraphviz.png', bbox_inches='tight')
plt.show()
示例5: plot_nx
# 需要导入模块: from networkx.drawing import nx_agraph [as 别名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 别名]
def plot_nx(bn,**kwargs):
"""
Draw BayesNet object from networkx engine
"""
g = nx.DiGraph(bn.E)
pos = graphviz_layout(g,'dot')
#node_size=600,node_color='w',with_labels=False
nx.draw_networkx(g,pos=pos, **kwargs)
plt.axis('off')
plt.show()
示例6: plot_network_with_results
# 需要导入模块: from networkx.drawing import nx_agraph [as 别名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 别名]
def plot_network_with_results(psstc, model, time=0):
G = create_network(psstc)
fig, axs = plt.subplots(1, 1, figsize=(12, 9))
ax = axs
line_color_dict = dict()
hour = 0
for i, b in branch_df.iterrows():
if model.ThermalLimit[i] != 0:
line_color_dict[(b['F_BUS'], b['T_BUS'])] = round(abs(model.LinePower[i, hour].value / model.ThermalLimit[i]), 2)
else:
line_color_dict[(b['F_BUS'], b['T_BUS'])] = 0
gen_color_dict = dict()
hour = 0
for i, g in generator_df.iterrows():
gen_color_dict[(i, g['GEN_BUS'])] = round(abs(model.PowerGenerated[i, hour].value / model.MaximumPowerOutput[i]), 2)
color_dict = line_color_dict.copy()
color_dict.update(gen_color_dict)
edge_color = list()
for e in G.edges():
try:
edge_color.append( color_dict[(e[0], e[1])] )
except KeyError:
edge_color.append( color_dict[(e[1], e[0])] )
ax.axis('off')
pos = graphviz_layout(G, prog='sfdp')
nx.draw_networkx_nodes(G, pos, list(generator_df.index),)
nx.draw_networkx_nodes(G, pos, list(bus_df.index), node_color='black',)
edges = nx.draw_networkx_edges(G, pos, edge_color=edge_color, edge_cmap=cmap, width=3)
nx.draw_networkx_edge_labels(G, pos, edge_labels=color_dict)
divider = make_axes_locatable(ax)
cax = divider.append_axes("left", size="5%", pad=0.05)
cb = plt.colorbar(edges, cax=cax)
cax.yaxis.set_label_position('left')
cax.yaxis.set_ticks_position('left')
# cb.set_label('Voltage (V)')
示例7: __init__
# 需要导入模块: from networkx.drawing import nx_agraph [as 别名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 别名]
def __init__(self, name, table, rootlane='timepoint', shift=None, log2=True, posgl=False, csv=False, groups=True):
"""
Initializes the class by providing the the common name ('name') of .gexf and .json files produced by
e.g. ParseAyasdiGraph(), the name of the file containing the filtered raw data ('table'), as produced by
Preprocess.save(), and the name of the column that contains sampling time points. Optional argument
'shift' can be an integer n specifying that the first n columns of the table should be ignored, or a
list of columns that should only be considered. If optional argument 'log2' is False, it is assumed that
the filtered raw data is in units of TPM instead of log_2(1+TPM). When optional argument 'posgl' is False,
a files name.posg and name.posgl are generated with the positions of the graph nodes for visualization.
When 'posgl' is True, instead of generating new positions, the positions stored in files name.posg and
name.posgl are used for visualization of the topological graph.
"""
UnrootedGraph.__init__(self, name, table, shift, log2, posgl, csv, groups)
self.rootlane = rootlane
self.root, self.leaf = self.find_root(self.get_dendrite())
self.g3, self.dicdend = self.dendritic_graph()
self.edgesize = []
self.dicedgesize = {}
self.edgesizeprun = []
self.nodesize = []
self.dicmelisa = {}
self.nodesizeprun = []
self.dicmelisaprun = {}
for ee in self.g3.edges():
yu = self.dicdend[int(ee[0].split('_')[0])][int(ee[0].split('_')[1])]
yu2 = self.dicdend[int(ee[1].split('_')[0])][int(ee[1].split('_')[1])]
self.edgesize.append(self.gl.subgraph(list(yu)+list(yu2)).number_of_edges()-self.gl.subgraph(yu).number_of_edges()
- self.gl.subgraph(yu2).number_of_edges())
self.dicedgesize[ee] = self.edgesize[-1]
for ee in self.g3.nodes():
lisa = []
for uu in self.dicdend[int(ee.split('_')[0])][int(ee.split('_')[1])]:
lisa += self.dic[uu]
self.nodesize.append(len(set(lisa)))
self.dicmelisa[ee] = set(lisa)
try:
from networkx.drawing.nx_agraph import graphviz_layout
self.posg3 = graphviz_layout(self.g3, 'sfdp')
except:
self.posg3 = networkx.spring_layout(self.g3)
self.dicdis = self.get_distroot(self.root)
pel2, tol = self.get_gene(self.rootlane, ignore_log=True)
self.pel = numpy.array([pel2[m] for m in self.pl])*tol
dr2 = self.get_distroot(self.root)
self.dr = numpy.array([dr2[m] for m in self.pl])
self.po = scipy.stats.linregress(self.pel, self.dr)
示例8: render
# 需要导入模块: from networkx.drawing import nx_agraph [as 别名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 别名]
def render(self, mode='human', close=False):
if self.simple_render:
observation = np.zeros((20, 20*self.chain_length))
observation[:, self.state*20:(self.state+1)*20] = 255
return observation
else:
# lazy loading of networkx and matplotlib to allow using the environment without installing them if
# necessary
import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout
import matplotlib.pyplot as plt
if not hasattr(self, 'G'):
self.states = list(range(self.chain_length))
self.G = nx.DiGraph(directed=True)
for i, origin_state in enumerate(self.states):
if i < self.chain_length - 1:
self.G.add_edge(origin_state,
origin_state + 1,
weight=0.5)
if i > 0:
self.G.add_edge(origin_state,
origin_state - 1,
weight=0.5, )
if i == 0 or i < self.chain_length - 1:
self.G.add_edge(origin_state,
origin_state,
weight=0.5, )
fig = plt.gcf()
if np.all(fig.get_size_inches() != [10, 2]):
fig.set_size_inches(5, 1)
color = ['y']*(len(self.G))
color[self.state] = 'r'
options = {
'node_color': color,
'node_size': 50,
'width': 1,
'arrowstyle': '-|>',
'arrowsize': 5,
'font_size': 6
}
pos = graphviz_layout(self.G, prog='dot', args='-Grankdir=LR')
nx.draw_networkx(self.G, pos, arrows=True, **options)
fig.canvas.draw()
data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
return data