本文整理汇总了Python中networkx.write_dot函数的典型用法代码示例。如果您正苦于以下问题:Python write_dot函数的具体用法?Python write_dot怎么用?Python write_dot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_dot函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
parser = argparse.ArgumentParser()
parser.add_argument('path', help = "target file or directory for summarization")
parser.add_argument("--posseed", help="boosting seed for biased LexRank", default = None)
parser.add_argument("--negseed", help="blocking seed for biased LexRank", default = None)
parser.add_argument("--stopfile", help="file containing custom stopwords")
parser.add_argument("-o", "--output", help = "output file name")
parser.add_argument("-l", "--length", help = "summary length in lines", default = 10)
parser.add_argument("--seed_posweight", help = "Weight for positive seed", default = 3)
parser.add_argument("--seed_negweight", help = "Weight for negative seed", default = .0001)
parser.add_argument("--ngrams", help = "N-gram number", default = 1)
#normalization doesn't work due to being inherent within scoring method
parser.add_argument("-n", "--is_norm", help = "Boolean flag for normalization", default = True)
args = parser.parse_args()
input_text = args.path
pos_seed = args.posseed
neg_seed = args.negseed
stopfile = args.stopfile
out_file = args.output
sum_length = int(args.length)
norm_flag = args.is_norm
pos_weight = float(args.seed_posweight)
neg_weight = float(args.seed_negweight)
ngram = int(args.ngrams)
corpus = Corpus(input_text).documents
output_checker(out_file)
if pos_seed == None and neg_seed == None:
LR_method = 'unbiased'
print LR_method
[term_matrix, normalized] = TDM(corpus, pos_seed, neg_seed, stopfile, norm_flag, ngram).matrix
pos_seed_vector = []
neg_seed_vector = []
else:
LR_method = 'biased'
if pos_seed == None:
pos_seed = ''
if neg_seed == None:
neg_seed = ''
[term_matrix, normalized, pos_seed_vector, neg_seed_vector] = TDM(corpus, pos_seed, neg_seed, stopfile, norm_flag, ngram).matrix
corpus = corpus[2:]
[scores,graph] = Graph(normalized, LR_method, pos_seed_vector, neg_seed_vector, pos_weight, neg_weight).sim_scores
#embed()
largest = networkx.strongly_connected_component_subgraphs(graph)[0]
A = networkx.to_agraph(largest)
#A.node_attr.update(shape='point')
A.node_attr.update(overlap='voronoi')
A.layout(prog='sfdp')
networkx.write_dot(largest, 'testgraph.gv')
A.draw('butterflyv2.png')
print_summary(corpus, scores, out_file, sum_length)
开发者ID:ScientistJeff,项目名称:pagekicker-community,代码行数:60,代码来源:PKgraph.py
示例2: salva_grafoNX_imagem
def salva_grafoNX_imagem(G):
"""
Salva grafos em formato png e dot
"""
nx.draw_graphviz(G)
nx.write_dot(G, 'relatorios/grafo_lei_vs_lei.dot')
P.savefig('relatorios/grafo_lei_vs_lei.png')
开发者ID:Ralpbezerra,项目名称:Supremo,代码行数:7,代码来源:grafos.py
示例3: runPRN
def runPRN():
#DG = readDotFile('/home/loenix/Documents/advogato_graph/advogato-graph-2014-03-16.dot')
DG = readDotFile('advogato-graph-latest.dot')
#DG = nx.DiGraph(nx.read_dot('/home/loenix/Documents/advogato_graph/advogato-graph-2014-03-16.dot'))
Eps = 0.000001 #set up epsilon
alpha = 0.15 # set alpha
#pick up a nodes far enough from the seed
#so that the subgraph on which APPR run will
#will be large enough
numHops = 4
rand = random.randint(0,len(DG.nodes())-1)
Seed = DG.nodes()[rand]
remoteSeed = getTrustorsOfExactHop(DG, Seed, numHops)
while remoteSeed == 0 :
Seed = DG.nodes()[rand]
remoteSeed = getTrustorsOfExactHop(DG, Seed, numHops)
#now got a seed which has 4 hop neighbor, run APPR
#print('seed is:' + Seed)
#print('nb of seed is: ' + str(DG.neighbors(Seed)))
#since the algr works on undirected graph
DG.to_undirected()
PR = PageRankNibble(DG, Seed, alpha, Eps)
#using the ranked nodes to form a subgraph.
H = DG.subgraph(PR)
nx.write_dot(H, 'pprResult.dot')
return H
开发者ID:bkelsey2216,项目名称:Advogato,代码行数:33,代码来源:runPRN.py
示例4: main
def main():
""" Application entry point """
args = process_arguments()
print('Loading data...')
data = load_data(args.infile)
people = list(set(m['sender'] for m in data) | set(r for m in data for r in m['recipients']))
counts = defaultdict(Counter)
for message in data:
counts[message['sender']].update(message['recipients'])
for person in people:
counts[person][person]=0
df = pd.DataFrame(counts)
connections = (df * df.T).stack().to_frame()
connections.index.names=['sender', 'recipient']
connections.reset_index(inplace=True)
subset = connections[connections['sender'] < connections['recipient']].copy()
subset.columns = ['sender', 'recipient', 'product']
subset['rank'] = subset['product'].rank(method='first', ascending=False)
ranking = subset.sort_values(by='rank').set_index(['rank'])
ranking.to_csv(args.outfile)
gr = nx.Graph()
for sender, recipient in zip(ranking['sender'], ranking['recipient']):
gr.add_edge(sender, recipient)
nx.write_dot(gr, 'thing.dot')
args.infile.close()
args.outfile.close()
开发者ID:csrhau,项目名称:sandpit,代码行数:31,代码来源:important_network.py
示例5: write_dot_graph
def write_dot_graph(self, dot_adr):
for n in self.GRAPH.nodes() :
self.GRAPH.node[n]["label"] = self.GRAPH.node[n]["contig"]+"_"+str(n)+"_"+self.GRAPH.node[n]["sens"]+"_"+self.GRAPH.node[n]["bi"]+"_"+str(self.GRAPH.node[n]["coords"])
if self.GRAPH.node[n]["bi"] == "b" :
self.GRAPH.node[n]["shape"] = "box"
if self.GRAPH.node[n]["sens"] == "f" :
self.GRAPH.node[n]["color"] = "green"
elif self.GRAPH.node[n]["sens"] == "r" :
self.GRAPH.node[n]["color"] = "red"
if "selected" in self.GRAPH.node[n].keys() :
self.GRAPH.node[n]["style"] = "filled"
for e in self.GRAPH.edges() :
self.GRAPH.edge[e[0]][e[1]]["label"] = self.GRAPH.edge[e[0]][e[1]]["length"]
if ((e[0] == "In" or e[0] == "Out") or (e[1] == "Out" or e[1] == "In")) and (self.GRAPH.edge[e[0]][e[1]]["length"] == 0):
self.GRAPH.edge[e[0]][e[1]]["style"] = "dashed"
self.GRAPH.edge[e[0]][e[1]]["color"] = "grey"
elif self.GRAPH.node[e[0]]["contig"] == self.GRAPH.node[e[1]]["contig"] and self.GRAPH.node[e[0]]["sens"] == "f" :
self.GRAPH.edge[e[0]][e[1]]["color"] = "green"
elif self.GRAPH.node[e[0]]["contig"] == self.GRAPH.node[e[1]]["contig"] and self.GRAPH.node[e[0]]["sens"] == "r" :
self.GRAPH.edge[e[0]][e[1]]["color"] = "red"
elif ((e[0] == "In" or e[0] == "Out") and self.GRAPH.node[e[1]]["sens"] == "f") or ((e[1] == "In" or e[1] == "Out") and self.GRAPH.node[e[0]]["sens"] == "f") :
self.GRAPH.edge[e[0]][e[1]]["color"] = "green"
elif ((e[0] == "In" or e[0] == "Out") and self.GRAPH.node[e[1]]["sens"] == "r") or ((e[1] == "In" or e[1] == "Out") and self.GRAPH.node[e[0]]["sens"] == "r") :
self.GRAPH.edge[e[0]][e[1]]["color"] = "red"
nx.write_dot(self.GRAPH, dot_adr)
开发者ID:bdartigues,项目名称:MIX,代码行数:25,代码来源:graph.py
示例6: write_graph
def write_graph(self, filename, problem_edges=[], max_edge=0.99):
G = nx.DiGraph()
print 'writing graph!'
print 'internal edges', self.directed_edges
for o in self.observations:
if o in self.anchors.values():
G.add_node(o, style='filled', color='red')
else:
G.add_node(o, style='filled', color='gray')
for e in self.directed_edges:
i = e[0]
j = e[1]
print ''
if e in problem_edges:
G.add_edge(i, j, color='red')
else:
G.add_edge(i, j, color='blue')
for e in self.failures:
i = e[0]
j = e[1]
if self.failures[e] < max_edge:
G.add_edge(i, j, color='green', weight=(1-self.failures[e])*10)
nx.write_dot(G, filename)
开发者ID:yhalpern,项目名称:noisy-or-tools,代码行数:27,代码来源:models.py
示例7: printDecoder
def printDecoder(self, fileName):
try:
NX.write_dot(self.decodingTree, fileName)
except:
import traceback
traceback.print_exc()
print ('Error in printing the decoding tree on file ' + fileName)
开发者ID:AmeyaVS,项目名称:trap-gen,代码行数:7,代码来源:decoder.py
示例8: main
def main():
if len(sys.argv) < 4:
print('Usage:')
print('python graphmaker.py [<input> Newick tree file] [<input> cutoff] [<output> DOT file]')
treefile = sys.argv[1]
cutoff = sys.argv[2]
dotfile = sys.argv[3]
try:
cutoff = float(cutoff)
except:
print('ERROR: expecting a float value for [cutoff]')
sys.exit()
try:
tree = Phylo.read(treefile, 'newick')
except:
print('ERROR: tree must be in Newick format')
sys.exit()
GM = GraphMaker(tree)
edges = GM.cluster(cutoff)
# generate networkx object
g = nx.Graph()
for tip1, neighbours in edges.iteritems():
for tip2, dist in neighbours.iteritems():
g.add_edge(tip1, tip2, dist=dist)
# each cluster can be examined using networkx functions; for example,
# clusters = nx.connected_components(g)
# export as GraphViz file
nx.write_dot(g, dotfile)
开发者ID:ArtPoon,项目名称:bioinfo,代码行数:33,代码来源:graphmaker.py
示例9: graph
def graph(end_with, start_with):
#g = xs.connection_graph()
g = signals.detailed_connection_graph(start_with=start_with,
end_with=end_with)
nx.write_dot(g, 'graph.dot')
fabric_api.local('dot -Tpng graph.dot -o graph.png')
开发者ID:sand8080,项目名称:solar,代码行数:7,代码来源:main.py
示例10: iterate
def iterate(n_iters):
for i in tqdm(xrange(n_iters)):
sampler.sample()
likelihoods.append(sampler.tree.marg_log_likelihood())
plt.figure()
plt.xlabel("Iterations", fontsize=fontsize)
plt.ylabel("Data Log Likelihood", fontsize=fontsize)
plt.plot(likelihoods)
plt.legend(loc='best', fontsize=12)
plt.savefig('unconstrained-likelihoods.png', bbox_inches='tight')
final_tree = sampler.tree.copy()
plt.figure()
plot_tree_2d(final_tree, X, pca)
for node in final_tree.dfs():
if node.is_leaf():
node.point = y[node.point]
plt.figure()
newick = final_tree.to_newick()
tree = Phylo.read(StringIO(newick), 'newick')
Phylo.draw_graphviz(tree, prog='neato')
plt.savefig('unconstrained-tree.png', bbox_inches='tight')
graph = Phylo.to_networkx(tree)
with open('unconstrained-tree.nwk', 'w') as fp:
print >>fp, newick,
nx.write_dot(graph, 'unconstrained-tree.dot')
plt.show()
开发者ID:sharadmv,项目名称:trees,代码行数:34,代码来源:run_sampler.py
示例11: sampleNodesFromGraph
def sampleNodesFromGraph(inputGraph, proportionToKeep):
# 0.9 ... keep 90% of the nodes, remove the rest along with incident edges
filename = inputGraph+'_sampled_'+str(proportionToKeep)
if os.path.isfile(filename):
G = nx.read_dot(filename)
print "Cached %s loaded." % filename
return G
Gorig = nx.read_dot(inputGraph)
G = nx.read_dot(inputGraph)
#G = nx.Graph(Gorig)
print "%s loaded." % inputGraph
nodes = Gorig.nodes()
random.shuffle(nodes)
N = len(nodes)
# keep k nodes
k = int(round(N*(1-proportionToKeep)))
for n in range(0,k):
G.remove_node(nodes[n])
nx.write_dot(G, filename)
print "\tGraph sampled. Original graph had %d nodes, sampled graph has %d nodes." % (len(Gorig.nodes()), len(G.nodes()))
return G
开发者ID:mudblood007,项目名称:RocData,代码行数:27,代码来源:pruneGraph.py
示例12: main
def main():
files = []
for i in range(1,26): files.append("db/Minna_no_nihongo_1.%02d.txt" % i)
for i in range(26,51): files.append("db/Minna_no_nihongo_2.%02d.txt" % i)
data = get_words_from_files(files)
words = [w for w in data]
#print words
G=nx.Graph()
for word1, word2 in itertools.combinations(words,2):
for w1 in word1[:-1]:
#print w1.encode('utf-8')
#print ud.name(w1)
if "CJK UNIFIED" in ud.name(w1) and w1 in word2:
#print word1.encode('utf-8'), word2.encode('utf-8')
G.add_edge(word1, word2)
break
nx.draw(G)
nx.write_dot(G, "kanjis.dot")
nx.write_graphml(G, "kanjis.graphml")
#plt.show()
words = G.nodes()
with open('kanjis.json', 'w') as f:
json.dump({'nodes': [{'name': i.encode('utf-8'),
'kana': data[i]['kana'],
'chapter': data[i]['chapter'],
'meaning': data[i]['meaning']} for i in G.nodes()],
'links': list(map(lambda u: {'source': words.index(u[0]), 'target': words.index(u[1])}, G.edges()))},
f, indent=2,)
开发者ID:agj,项目名称:KanjiNetwork,代码行数:33,代码来源:kanjis.py
示例13: build_network
def build_network(self, nodes, nodesizes, weights,
outfile = 'network.dot', nodeprop=None):
'''
Not working yet
Nodes represents the states
'''
nodes=np.array(nodes)
import networkx as nx
G = nx.Graph()
if nodeprop is not None:
for i in range(nodes.size):
G.add_node(int(nodes[i]), size=int(nodesizes[i]),
label=int(nodes[i]), prop=nodeprop[i])
else:
for i in range(nodes.size):
G.add_node(int(nodes[i]), size=int(nodesizes[i]),
label=int(nodes[i]))
for i in range(weights.shape[0]):
w = weights[i, 2]
G.add_edge(int(weights[i, 0]), int(weights[i, 1]),
weight=float(w))
nx.write_dot(G, outfile)
outfile1 = outfile.replace('.dot', '.gml')
nx.write_gml(G, outfile1)
开发者ID:smgusing,项目名称:parallelclusterer,代码行数:27,代码来源:utils.py
示例14: export
def export(self, name=None, valuation=None):
tmpdir = 'tmp/'
# dotpgm = 'dot'
filename = tmpdir + self.automaton.graph['name']
if name:
filename = tmpdir + name
dotfile = filename + '.dot'
# pngfile = filename + '.png'
if valuation:
# We now want to remove any edges that are not in the valuation
for fv, tv, key, dct in self.get_transitions(keys=True):
if valuation.get_var_val(dct['f_var']) == 0:
self.automaton.remove_edge(fv, tv, key=key)
else:
fvar = str(valuation.get_var_val(dct['f_var']))
self.automaton.edge[fv][tv][key]['label'] = fvar
# Now we want to remove any orphaned nodes
for node, deg in self.automaton.degree().iteritems():
if deg == 0:
self.automaton.remove_node(node)
networkx.write_dot(self.automaton, dotfile)
开发者ID:it-apv,项目名称:alternator,代码行数:25,代码来源:automata.py
示例15: genome_animation
def genome_animation(genomes_files, indir, outdir=None):
# by default the same
if outdir == None :
outdir = indir
# create dot files
last_genome_file = genomes_files[-1]
last_genome = process_graph(indir+'/'+last_genome_file)
for gf in genomes_files :
graph_of_g = graph_from_graph(last_genome, indir+'/'+gf)
nx.write_dot(graph_of_g, outdir+'/'+gf[:-4]+'.dot')
# create png files
png_filenames = generate_fname_seq(len(genomes_files), 'png')
i=0
for gf in genomes_files :
dot2png(outdir+'/'+gf[:-4]+'.dot', outdir+'/'+png_filenames[i])
i=i+1
# print the command line to create the movie
zpad = len(str(i))
cmd_line = 'ffmpeg -framerate 1 -i '+outdir+'/'+'%0'+str(zpad)+'d.png -c:v libx264 -pix_fmt yuv420p '+outdir+'/out.mp4';
print 'To create the movies run the following command:'
print cmd_line
开发者ID:spikomino,项目名称:roborobo2,代码行数:25,代码来源:genome2graph.py
示例16: create_phylo_tree
def create_phylo_tree(fname, save=False, dotfile='philo.dot', xover=False, prune=False):
colors = ['chartreuse', 'chocolate', 'cadetblue', 'cornflowerblue', 'cyan',
'darkorange', 'darkviolet', 'deeppink']
#TODO check how to define hexadecimal colors for GraphViz
colorsH = ["#7FFF00", "#D2691E", "#5F9EA0", "#6495ED", "#00FFFF",
"#FF8C00", "#9400D3", "#F1493"]
# create a graph
G=nx.MultiDiGraph()
# fill the lists with all the genes
gl = process_file(fname)
# create the phylo-tree
for n in gl.keys():
G.add_node(n) # the root node (the initial genome)
G.node[n]['agent'] = n
G.node[n]['id'] = n
G.node[n]['color'] = colors[n%len(colors)]
trac_genome(gl, n, G, colors)
if xover:
G=add_dad_links(G,gl)
if prune:
id_last_epoch= max(G.nodes()) - len(gl.keys()) + 1
nb_epochs= len(G.nodes())/len(gl.keys())
G=prune_tree(G,id_last_epoch,nb_epochs)
# write the file
if save :
nx.write_dot(G, dotfile)
return G
开发者ID:inakiFernandez,项目名称:roborobo3,代码行数:33,代码来源:puregenome2graph.py
示例17: writeExprTree
def writeExprTree(G,filename='ExprTree.dot'):
"""
Writes a tree in the DOT format:
- http://en.wikipedia.org/wiki/DOT_language
- http://www.graphviz.org/
"""
nx.write_dot(G,filename)
开发者ID:architkumar02,项目名称:murphs-code-repository,代码行数:7,代码来源:nxExprTree.py
示例18: to_dot_file
def to_dot_file(self, filename):
'''把图写入到dot文件中,不对原图做什么改变
新图的节点只是字符串。
'''
new_graph = nx.DiGraph()
for start, end, data in self.edges_iter(data = True):
port_pair = data['port_pair']
connection = data['connection']
edge = [start, end] # 存储边的起点和终点
node_id =['',''] # 存储节点的名称
node_data =[{},{}] # 存储要打印到dot中的信息
for i in range(2):
# 当前节点是prim 或者是 port
is_prim = True if isinstance(edge[i], cc.circut_module) else False
# prim和port的数据属性不同,根据判断为生成dot节点的名称,和节点附属的['shape']数据
node_name = '_d_'+edge[i].name[1:] if edge[i].name[0]=='\\' else edge[i].name
node_id[i] = edge[i].cellref+node_name if is_prim else\
edge[i].port_type+node_name
# prim为box形状(盒子),port为invtriangle形状(倒三角)
node_data[i]['shape'] = 'box' if is_prim else 'invtriangle'
new_graph.add_node(node_id[i],node_data[i])
new_graph.add_edge(node_id[0], node_id[1])
try:
nx.write_dot(new_graph, filename)
except Exception, e:
print "Warning: Cannot write dot file", e
开发者ID:litaotju,项目名称:netlistx,代码行数:26,代码来源:circuitgraph.py
示例19: export_graph
def export_graph(
graph_in,
base_dir=None,
show=False,
use_execgraph=False,
show_connectinfo=False,
dotfilename="graph.dot",
format="png",
simple_form=True,
):
""" Displays the graph layout of the pipeline
This function requires that pygraphviz and matplotlib are available on
the system.
Parameters
----------
show : boolean
Indicate whether to generate pygraphviz output fromn
networkx. default [False]
use_execgraph : boolean
Indicates whether to use the specification graph or the
execution graph. default [False]
show_connectioninfo : boolean
Indicates whether to show the edge data on the graph. This
makes the graph rather cluttered. default [False]
"""
graph = deepcopy(graph_in)
if use_execgraph:
graph = generate_expanded_graph(graph)
logger.debug("using execgraph")
else:
logger.debug("using input graph")
if base_dir is None:
base_dir = os.getcwd()
if not os.path.exists(base_dir):
os.makedirs(base_dir)
outfname = fname_presuffix(dotfilename, suffix="_detailed.dot", use_ext=False, newpath=base_dir)
logger.info("Creating detailed dot file: %s" % outfname)
_write_detailed_dot(graph, outfname)
cmd = "dot -T%s -O %s" % (format, outfname)
res = CommandLine(cmd, terminal_output="allatonce").run()
if res.runtime.returncode:
logger.warn("dot2png: %s", res.runtime.stderr)
pklgraph = _create_dot_graph(graph, show_connectinfo, simple_form)
outfname = fname_presuffix(dotfilename, suffix=".dot", use_ext=False, newpath=base_dir)
nx.write_dot(pklgraph, outfname)
logger.info("Creating dot file: %s" % outfname)
cmd = "dot -T%s -O %s" % (format, outfname)
res = CommandLine(cmd, terminal_output="allatonce").run()
if res.runtime.returncode:
logger.warn("dot2png: %s", res.runtime.stderr)
if show:
pos = nx.graphviz_layout(pklgraph, prog="dot")
nx.draw(pklgraph, pos)
if show_connectinfo:
nx.draw_networkx_edge_labels(pklgraph, pos)
开发者ID:veenasomareddy,项目名称:nipype,代码行数:60,代码来源:utils.py
示例20: testDot
def testDot(self):
self.assertEqual( self.g.number_of_edges(), 4 )
self.assertEqual( self.g.number_of_edges(), 4 )
nx.write_dot( self.g, './test.dot' )
g1 = nx.read_dot( './test.dot' )
self.assertEqual( g1.number_of_edges(), self.g.number_of_edges() )
self.assertEqual( g1.number_of_edges(), 4 )
开发者ID:SuperbBob,项目名称:trust-metrics,代码行数:7,代码来源:testXDiGraph.py
注:本文中的networkx.write_dot函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论