本文整理汇总了Python中networkx.graphviz_layout函数的典型用法代码示例。如果您正苦于以下问题:Python graphviz_layout函数的具体用法?Python graphviz_layout怎么用?Python graphviz_layout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了graphviz_layout函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_graph
def plot_graph(self, run_name, condor_path):
# Graph one plots the memory utilization of various steps
plt.figure(1, figsize=(30, 30))
plt.axis("off")
plt.title(run_name + "/" + "Condor Memory Utilization Scheme")
pos = nx.graphviz_layout(self.G)
nx.draw_networkx(self.G, pos, k=10, with_labels=False, node_size=1500, node_color=self.memory_colors())
nx.draw_networkx_labels(self.G, pos, labels=self.memory_labels())
plt.savefig(condor_path + run_name + "/" + "CondorMemoryUtilization.png")
plt.clf()
# Graph two plots the CPU utilization of various steps
plt.figure(2, figsize=(30, 30))
plt.axis("off")
plt.title("Condor CPU Utilization Scheme")
pos = nx.graphviz_layout(self.G)
nx.draw_networkx(self.G, pos, k=10, with_labels=False, node_size=1500, node_color=self.cpu_colors())
nx.draw_networkx_labels(self.G, pos, self.cpu_labels())
plt.savefig(condor_path + run_name + "/" + "CondorCpuUtilization.png")
plt.clf()
# Graph three plots the GPU utilization of various steps
plt.figure(3, figsize=(30, 30))
plt.axis("off")
plt.title("Condor GPU Utilization Scheme")
pos = nx.graphviz_layout(self.G)
nx.draw_networkx(self.G, pos, k=10, with_labels=False, node_size=1500, node_color=self.gpu_colors())
nx.draw_networkx_labels(self.G, pos, self.gpu_labels())
plt.savefig(condor_path + run_name + "/" + "CondorGpuUtilization.png")
plt.clf()
示例2: position_friends
def position_friends(request, engine, width, height, widthoffset=0, auto = False):
print "Positioning friends"
width = width-widthoffset
ratio = float(width)/float(height)
dajax = Dajax()
s = request.session
user = s['fbuser']
print "Got fbuser object"
p = Person.objects.get(id = user.id)
print "AJAX checking if connections_ready = " +str(p.connections_ready)
#Check if the connections are ready to be returned; if not tell client to wait 5s
if (not p.connections_ready):
print "Connections not ready"
dajax.add_data({'time':3000, 'auto':auto}, 'grapher.waitToPosition')
return dajax.json()
nodes = user.get_friend_ids()
print "Got nodes"
links = user.get_friends_links()
print "Got links"
#print links
G_wrapper = GraphWrapper(nodes, links)
G = G_wrapper.G
print "Producing layout"
if (engine=="sfdp"):
layout=nx.graphviz_layout(G, prog='sfdp', args="-Gratio=%f -GK=1.5" % (ratio))
elif (engine=="twopi"):
layout=nx.graphviz_layout(G, prog='twopi', args="-Gratio=%f" % ratio)
else:
#Invalid layout engine?
return dajax.json()
x_coords = [p[0] for p in layout.values()]
y_coords = [p[1] for p in layout.values()]
min_x = min(x_coords)
max_x = max(x_coords)
min_y = min(y_coords)
max_y = max(y_coords)
x_shift = -1 * min_x
y_shift = -1*min_y
x_scale = float(width-20)/float(max_x-min_x)
y_scale = float(height-20)/float(max_y-min_y)
scaled_layout = {}
for node in layout:
x = int((layout[node][0] + x_shift) * x_scale)+10+widthoffset
y = int((layout[node][1] + y_shift) * y_scale)+10
scaled_layout[node] = (x,y)
#print scaled_layout
if auto:
dajax.add_data(scaled_layout, 'grapher.auto_set_positions')
else:
dajax.add_data(scaled_layout, 'grapher.set_positions')
return dajax.json()
示例3: as_path_plot
def as_path_plot(self,as_path, prefix):
'''This method accpets the list of as-path to plot for the
selected prefix as per the GUI. It uses networkx module.
The Nodes represent the AS and the edges represent the
AS connectivity.
'''
G = nx.Graph()
l= as_path
for i,a in enumerate(l):
#print a, type(a), len(a)
G.add_node(a[-1])
for i in xrange(len(a)):
if i == len(a)-1:
break
G.add_node(a[i])
G.add_edge(a[i],a[i+1])
# plt.title("draw_networkx")
# plt.savefig('abcd.png',dpi=500, facecolor='w', edgecolor='w',orientation='landscape', papertype=None, format=None,transparent=False, bbox_inches=None, pad_inches=0.8)
plt.title("AS Path for "+prefix)
pos=nx.graphviz_layout(G,prog='dot')
plt.figure(1,figsize=(10,8))
#nx.draw_networkx(G,pos)
nx.draw(G,pos,with_labels=True,arrows=True, font_size = 9,edge_color='r', node_color='b')
plt.savefig(prefix+'_as_path.png',pad_inches = 0.8)
plt.show()
示例4: plot_func
def plot_func(play, stats):
generation = stats["generation"]
best = stats["generation_best"]
every = play.config["live_plot"].get("every", 100)
if generation == 0:
plt.figure(figsize=(10, 8))
if (generation % every) == 0:
plt.clf()
# create graph
graph = nx.DiGraph()
traverse_tree(best.root, graph)
labels = dict((n, d["label"]) for n, d in graph.nodes(data=True))
pos = nx.graphviz_layout(graph, prog='dot')
nx.draw(
graph,
pos,
with_labels=True,
labels=labels,
arrows=False,
node_shape=None
)
# plot graph
plt.draw()
plt.pause(0.0001) # very important else plot won't be displayed
示例5: draw
def draw(graph):
pos = nx.graphviz_layout(graph, prog='sfdp', args='')
list_nodes = graph.nodes()
plt.figure(figsize=(20,10))
nx.draw(graph, pos, node_size=20, alpha=0.4, nodelist=list_nodes, node_color="blue", with_labels=False)
plt.savefig('graphNX.png')
plt.show()
示例6: plot_co_x
def plot_co_x(cox, start, end, size = (20,20), title = '', weighted=False, weight_threshold=10):
""" Plotting function for keyword graphs
Parameters
--------------------
cox: the coword networkx graph; assumes that nodes have attribute 'topic'
start: start year
end: end year
"""
plt.figure(figsize=size)
plt.title(title +' %s - %s'%(start,end), fontsize=18)
if weighted:
elarge=[(u,v) for (u,v,d) in cox.edges(data=True) if d['weight'] >weight_threshold]
esmall=[(u,v) for (u,v,d) in cox.edges(data=True) if d['weight'] <=weight_threshold]
pos=nx.graphviz_layout(cox) # positions for all nodes
nx.draw_networkx_nodes(cox,pos,
node_color= [s*4500 for s in nx.eigenvector_centrality(cox).values()],
node_size = [s*6+20 for s in nx.degree(cox).values()],
alpha=0.7)
# edges
nx.draw_networkx_edges(cox,pos,edgelist=elarge,
width=1, alpha=0.5, edge_color='black') #, edge_cmap=plt.cm.Blues
nx.draw_networkx_edges(cox,pos,edgelist=esmall,
width=0.3,alpha=0.5,edge_color='yellow',style='dotted')
# labels
nx.draw_networkx_labels(cox,pos,font_size=10,font_family='sans-serif')
plt.axis('off')
else:
nx.draw_graphviz(cox, with_labels=True,
alpha = 0.8, width=0.1,
fontsize=9,
node_color = [s*4 for s in nx.eigenvector_centrality(cox).values()],
node_size = [s*6+20 for s in nx.degree(cox).values()])
示例7: colorSubcomps
def colorSubcomps(self, G, prog="neato", layout=None):
C = nx.connected_component_subgraphs(G)
pos = nx.graphviz_layout(G, prog=prog) if layout == None else layout
for g in C:
c = [random.random()] * nx.number_of_nodes(g) # random color...
nx.draw(g, pos, node_size=40, node_color=c, vmin=0.0, vmax=1.0, with_labels=False)
示例8: Main
def Main():
G = kw2Jd(searchterm)
H = nx.Graph(G)
font = {'fontname': 'Arial',
'color': 'k',
'fontweight': 'bold',
'fontsize': 14}
plt.rcParams['text.usetex'] = False
plt.figure(figsize=(8, 8))
plt.title("PZ", font)
plt.axis('off')
plt.text(0.5, .95, searchterm,
horizontalalignment='center', transform=plt.gca().transAxes)
try:
pos = nx.graphviz_layout(H)
except:
pos = nx.spring_layout(H, iterations=20)
nx.draw_networkx_edges(
H, pos, alpha=0.1, node_size=0, edge_color='w', width=3)
nx.draw_networkx_labels(H, pos, fontsize=12)
nodesize = [salary.get(v, 0) ** 2 for v in H]
colorcoding = [supply.get(v, 10000) / (openings.get(v, 1) + 1) for v in H]
linewidths = [
(abs(trends.get(v, 0)) - trends.get(v, 10000)) / 10 for v in H]
nodes = H.nodes()
nx.draw_networkx_nodes(H, pos, nodelist=nodes, node_size=nodesize, linewidths=linewidths, cmap=plt.cm.Blues, vmin=min(
colorcoding), vmax=100, node_color=colorcoding)
plt.savefig("pz-networkx.png", dpi=75)
plt.show()
示例9: startGame
def startGame(self):
print "starting game", self.configuration
self.startNode = [loadGame(self.configuration).toString()]
threads = []
for i in range(10):
t = threading.Thread(target=self.ant, args=(i,))
threads.append(t)
t.start()
print "Waiting..."
for t in threads:
t.join()
print "Waiting done"
# nx.draw(self.stateSpace)
myBoard = loadGame(self.configuration).toString()
pos=nx.graphviz_layout(self.stateSpace,prog='neato')
nx.draw(self.stateSpace,pos=pos,node_size=20)
nx.draw_networkx_nodes(self.stateSpace,pos,
nodelist=[myBoard],
node_color='g',
node_size=100)
nx.draw_networkx_nodes(self.stateSpace,pos,
nodelist=list(self.winNodes),
node_color='b',
node_size=100)
# A = nx.to_agraph(self.stateSpace)
# A.layout(prog='neato', color='red')
# A.draw('color.png')
plt.show()
示例10: prettyPlotter
def prettyPlotter(self, l=None, filename=None):
"""
Metod służy do rysowania grafu reprezentującego sieć, w którym węzły należące do tej samej grupy są oznaczone jednym kolorem.
@type l: list
@param l: lista list węzłów podzielonych na grupy
@param filename: nazwa pliku PNG z wynikowym obrazem
"""
nodeList = l
colorList = [0] * self.graph.number_of_nodes()
for nbunch in nodeList:
for n in nbunch:
colorList[self.graph.nodes().index(n)] = nodeList.index(nbunch)
import matplotlib.pyplot as plt
pos = nx.graphviz_layout(self.graph, prog='neato')
plt.figure()
plt.axis('off')
nx.draw(self.graph, pos, node_color=colorList, with_labels=False)
if filename:
import config
filename = config.PLOT_OUT_DIR+filename
plt.savefig(filename)
else:
plt.show()
示例11: draw_graph
def draw_graph(self, my_list=None):
# pos = nx.spring_layout(self.G, iterations=20)
pos = nx.graphviz_layout(self.G, prog='sfdp', root='downlod_0', args="-Grankdir=LR")
#pos = nx.spring_layout(self.G,fixed = ['r1_c1'], scale=2)
#print(pos)
#pos = self.h_recur(self.G, 'download_0')
#nx.draw(self.G, pos=pos, with_labels=True)
for node in self.G.nodes():
self.G.node[node]['category'] = 'type_A'
if my_list:
for my_nodes2 in my_list:
self.G.node[my_nodes2]['category'] = 'critical_path'
color_map = {'type_A':'y', 'critical_path':'#FFC266'}
## construct a list of colors then pass to node_color
if my_list:
nx.draw(self.G, pos=pos, node_size=200, node_color=[color_map[self.G.node[node]['category']] for node in self.G])
else:
nx.draw(self.G, pos=pos, node_size=200, node_color='y')
node_labels = nx.get_node_attributes(self.G, 'id')
nx.draw_networkx_labels(self.G, pos, labels=node_labels, font_size=8, font_color='r', font_weight='bold',
font_family='sans-serif')
"""edge_labels = nx.get_edge_attributes(self.G, 'weight')
for key, value in edge_labels.items():
edge_labels[key] = round(value, 4)"""
#print('edge lbl', edge_labels)
#nx.draw_networkx_edge_labels(self.G, pos, labels=edge_labels)
plt.show()
示例12: visualize
def visualize(tree, custom_alpha=0.5, labels=False):
G = nx.Graph(tree)
pos = nx.graphviz_layout(G, prog='twopi', args='', root='root')
plt.figure(figsize=(10, 10))
nx.draw(G, pos, node_size=0, alpha=custom_alpha, node_color="blue", with_labels=labels)
plt.axis('equal')
plt.show()
示例13: get
def get(self, request, name="root", *args, **kwargs):
import networkx as nx
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import nxedges
plt.figure(figsize=(10, 8))
g = nx.DiGraph()
labels = {}
for service in Service.objects.all():
g.add_node(service.id)
if len(service.name) > 8:
labels[service.id] = service.name[:8] + "\n" + service.name[8:]
else:
labels[service.id] = service.name
for tenant in CoarseTenant.objects.all():
if (not tenant.provider_service) or (not tenant.subscriber_service):
continue
g.add_edge(tenant.subscriber_service.id, tenant.provider_service.id)
pos = nx.graphviz_layout(g)
nxedges.xos_draw_networkx_edges(g, pos, arrow_len=30)
nx.draw_networkx_nodes(g, pos, node_size=5000)
nx.draw_networkx_labels(g, pos, labels, font_size=12)
# plt.axis('off')
plt.savefig("/tmp/foo.png")
return HttpResponse(open("/tmp/foo.png", "r").read(), content_type="image/png")
示例14: draw
def draw(self):
if os.path.exists(self.service_dep_file_path):
graph=nx.DiGraph()
service_dep_file_handle=open(self.service_dep_file_path,'r')
try:
raw_connection_instance=service_dep_file_handle.readline()
while raw_connection_instance:
connection_instance=raw_connection_instance.strip('\n')
sub_str=connection_instance.split(' ')
source_sub_str=sub_str[0]
destination_sub_str=sub_str[1]
localhost=sub_str[0].split(',')
if len(destination_sub_str)==0:
destination_sub_str='remote process'
graph.add_node(source_sub_str)
graph.add_node(destination_sub_str)
graph.add_edge(source_sub_str,destination_sub_str)
graph.add_edge(source_sub_str,localhost[0])
raw_connection_instance=service_dep_file_handle.readline()
# Set the attributes of the grpah
# pos=nx.spring_layout(graph,dim=2,iterations=5)
pos=nx.graphviz_layout(graph,prog='dot')
nx.draw(graph,pos,edge_color='b',font_size=15)
plt.show()
finally:
service_dep_file_handle.close()
示例15: erd
def erd(self, subset=None, prog='dot'):
"""
plot the schema's entity relationship diagram (ERD).
The layout programs can be 'dot' (default), 'neato', 'fdp', 'sfdp', 'circo', 'twopi'
"""
if not subset:
g = self.graph
else:
g = self.graph.copy()
for i in g.nodes():
if i not in subset:
g.remove_node(i)
def tableList(tier):
return [i for i in g if self.tables[i].tier==tier]
pos=nx.graphviz_layout(g,prog=prog,args='')
plt.figure(figsize=(8,8))
nx.draw_networkx_edges(g, pos, alpha=0.3)
nx.draw_networkx_nodes(g, pos, nodelist=tableList('manual'),
node_color='g', node_size=200, alpha=0.3)
nx.draw_networkx_nodes(g, pos, nodelist=tableList('computed'),
node_color='r', node_size=200, alpha=0.3)
nx.draw_networkx_nodes(g, pos, nodelist=tableList('imported'),
node_color='b', node_size=200, alpha=0.3)
nx.draw_networkx_nodes(g, pos, nodelist=tableList('lookup'),
node_color='gray', node_size=120, alpha=0.3)
nx.draw_networkx_labels(g, pos, nodelist = subset, font_weight='bold', font_size=9)
nx.draw(g,pos,alpha=0,with_labels=False)
plt.show()