本文整理汇总了Python中networkx.write_dot函数的典型用法代码示例。如果您正苦于以下问题:Python write_dot函数的具体用法?Python write_dot怎么用?Python write_dot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_dot函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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')
示例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
示例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()
示例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)
示例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)
示例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)
示例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)
示例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')
示例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()
示例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
示例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,)
示例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)
示例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)
示例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