本文整理匯總了Python中networkx.draw_networkx_nodes方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.draw_networkx_nodes方法的具體用法?Python networkx.draw_networkx_nodes怎麽用?Python networkx.draw_networkx_nodes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類networkx
的用法示例。
在下文中一共展示了networkx.draw_networkx_nodes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: graph_att_head
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def graph_att_head(M, N, weight, ax, title):
"credit: Jinjing Zhou"
in_nodes=len(M)
out_nodes=len(N)
g = nx.bipartite.generators.complete_bipartite_graph(in_nodes,out_nodes)
X, Y = bipartite.sets(g)
height_in = 10
height_out = height_in
height_in_y = np.linspace(0, height_in, in_nodes)
height_out_y = np.linspace((height_in - height_out) / 2, height_out, out_nodes)
pos = dict()
pos.update((n, (1, i)) for i, n in zip(height_in_y, X)) # put nodes from X at x=1
pos.update((n, (3, i)) for i, n in zip(height_out_y, Y)) # put nodes from Y at x=2
ax.axis('off')
ax.set_xlim(-1,4)
ax.set_title(title)
nx.draw_networkx_nodes(g, pos, nodelist=range(in_nodes), node_color='r', node_size=50, ax=ax)
nx.draw_networkx_nodes(g, pos, nodelist=range(in_nodes, in_nodes + out_nodes), node_color='b', node_size=50, ax=ax)
for edge in g.edges():
nx.draw_networkx_edges(g, pos, edgelist=[edge], width=weight[edge[0], edge[1] - in_nodes] * 1.5, ax=ax)
nx.draw_networkx_labels(g, pos, {i:label + ' ' for i,label in enumerate(M)},horizontalalignment='right', font_size=8, ax=ax)
nx.draw_networkx_labels(g, pos, {i+in_nodes:' ' + label for i,label in enumerate(N)},horizontalalignment='left', font_size=8, ax=ax)
示例2: plot_alerts
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def plot_alerts(_g, _bank_accts, _output_png):
bank_ids = _bank_accts.keys()
cmap = plt.get_cmap("tab10")
pos = nx.nx_agraph.graphviz_layout(_g)
plt.figure(figsize=(12.0, 8.0))
plt.axis('off')
for i, bank_id in enumerate(bank_ids):
color = cmap(i)
members = _bank_accts[bank_id]
nx.draw_networkx_nodes(_g, pos, members, node_size=300, node_color=color, label=bank_id)
nx.draw_networkx_labels(_g, pos, {n: n for n in members}, font_size=10)
edge_labels = nx.get_edge_attributes(_g, "label")
nx.draw_networkx_edges(_g, pos)
nx.draw_networkx_edge_labels(_g, pos, edge_labels, font_size=6)
plt.legend(numpoints=1)
plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
plt.savefig(_output_png, dpi=120)
示例3: draw_transmat_graph_inner
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def draw_transmat_graph_inner(G, edge_threshold=0, lw=1, ec='0.2', node_size=15):
num_states = G.number_of_nodes()
edgewidth = [ d['weight'] for (u,v,d) in G.edges(data=True)]
edgewidth = np.array(edgewidth)
edgewidth[edgewidth<edge_threshold] = 0
npos=circular_layout(G, scale=1, direction='CW')
nx.draw_networkx_edges(G, npos, alpha=1.0, width=edgewidth*lw, edge_color=ec)
nx.draw_networkx_nodes(G, npos, node_size=node_size, node_color='k',alpha=1.0)
ax = plt.gca()
ax.set_aspect('equal')
return ax
示例4: draw_transmat_graph_outer
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def draw_transmat_graph_outer(Go, Gi, edge_threshold=0, lw=1, ec='0.2', nc='k', node_size=15):
num_states = Go.number_of_nodes()
edgewidth = [ d['weight'] for (u,v,d) in Go.edges(data=True)]
edgewidth = np.array(edgewidth)
edgewidth[edgewidth<edge_threshold] = 0
npos=double_circular_layout(Gi, scale=1, direction='CW')
nx.draw_networkx_edges(Go, npos, alpha=1.0, width=edgewidth*lw, edge_color=ec)
nx.draw_networkx_nodes(Go, npos, node_size=node_size, node_color=nc,alpha=1.0)
ax = plt.gca()
ax.set_aspect('equal')
return ax
示例5: plot_baseline
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def plot_baseline(network):
edges = set(network.edges())
pos = {n: (n.lng, n.lat) for n in network.nodes()}
labels = {n: n.location.city for n in network.nodes() if isinstance(n, Transceiver)}
city_labels = set(labels.values())
for n in network.nodes():
if n.location.city and n.location.city not in city_labels:
labels[n] = n.location.city
city_labels.add(n.location.city)
label_pos = pos
fig = figure()
kwargs = {'figure': fig, 'pos': pos}
plot = draw_networkx_nodes(network, nodelist=network.nodes(), node_color='#ababab', **kwargs)
draw_networkx_edges(network, edgelist=edges, edge_color='#ababab', **kwargs)
draw_networkx_labels(network, labels=labels, font_size=14, **{**kwargs, 'pos': label_pos})
axis('off')
show()
示例6: plot_network
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def plot_network(self, G, status, pos=None, nodelist=None, colordict={'S':'#009a80','I':'#ff2020', 'R':'gray'}, **nx_kwargs):
r'''
Plots the network in the axes self.networkx_ax. Nodes are colored according to their status.
if no ordered nodelist is provided, then the nodes are plotted so that 'I' nodes appear on top, while the order of the 'S' and 'R' nodes is random. When the network is very dense this highlights 'I' nodes and allows the final state to more accurately represent the proportion of nodes having each status.
'''
colorlist = []
if pos is None:
pos = nx.spring_layout(G)
if nodelist is None:
nodelist = list(G.nodes())
I_nodes = [node for node in nodelist if status[node] == 'I']
other_nodes = [node for node in nodelist if status[node]!='I']
random.shuffle(other_nodes)
nodelist = other_nodes + I_nodes
edgelist = list(G.edges())
else:
nodeset = set(nodelist)
edgelist = [edge for edge in G.edges() if edge[0] in nodeset and edge[1] in nodeset]
for node in nodelist:
colorlist.append(colordict[status[node]])
nx.draw_networkx_edges(G, pos, edgelist=edgelist, ax = self.network_axes, **nx_kwargs)
nx.draw_networkx_nodes(G, pos, nodelist = nodelist, node_color=colorlist, ax=self.network_axes, **nx_kwargs)
self.network_axes.set_xticks([])
self.network_axes.set_yticks([])
開發者ID:springer-math,項目名稱:Mathematics-of-Epidemics-on-Networks,代碼行數:26,代碼來源:class_based_visualization.py
示例7: _initialize
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def _initialize(self):
initial_status = EoN.get_statuses(self.G, self.node_history, self.frame_times[0])
colorlist = [self.colordict[initial_status[node]] for node in self.nodelist]
nodeset = {node for node in self.nodelist}
edgelist = [edge for edge in self.G.edges() if edge[0] in nodeset and edge[1] in nodeset]
nx.draw_networkx_edges(self.G, pos=self.pos, edgelist=edgelist, ax = self.network_axes)
drawn_nodes = nx.draw_networkx_nodes(self.G, pos=self.pos, ax = self.network_axes, nodelist = self.nodelist, color=colorlist, **self.kwargs)
Inodelist = [node for node in self.nodelist if initial_status[node] == 'I']
drawn_I = [nx.draw_networkx_nodes(self.G, pos=self.pos, nodelist=Inodelist, color = self.colordict['I'], ax = self.network_axes, **self.kwargs)]
self.network_axes.set_xticks([])
self.network_axes.set_yticks([])
time_markers = [None for ax in self.timeseries_axi]
self._highlight_time(self.frame_times[0], time_markers)
return drawn_nodes, drawn_I, time_markers
開發者ID:springer-math,項目名稱:Mathematics-of-Epidemics-on-Networks,代碼行數:20,代碼來源:class_based_visualization.py
示例8: plot_subgraph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def plot_subgraph(self, region_start, region_stop, seq_name, neighbours=0):
"""
Return a plot of a sub-graph from a defined region with positions relative to some of the sequences.
:param region_start: Start position (bp)
:param region_stop: Stop position (bp)
:param seq_name: Sequence ID that the bp positions are relative to.
:param neighbours: Number of neighbours to be included. Currently testing, only 1 level available.
:return: Plots a netowrkx + matplotlib figure of the region subgraph.
"""
sub_graph = extract_region_subgraph(self, region_start, region_stop, seq_name, neighbours=neighbours)
pos = nx.spring_layout(sub_graph)
nx.draw_networkx_nodes(sub_graph, pos, cmap=plt.get_cmap('jet'), node_size=300)
nx.draw_networkx_labels(sub_graph, pos)
nx.draw_networkx_edges(sub_graph, pos, arrows=True)
plt.show()
示例9: replay
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def replay(self, graph):
"""Draw the given graph."""
fig, ax = plt.subplots(frameon=False) # pylint:disable=invalid-name
plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
node_pos = graph.node_coordinates
def _update(num):
ax.clear()
fig.canvas.set_window_title(f'{graph.name} - Iteration ({num+1}/{len(self.__edge_colors)})')
nodes_artist = nx.draw_networkx_nodes(graph.networkx_graph, pos=node_pos, ax=ax, node_color=self.__node_color)
labels_artist = nx.draw_networkx_labels(graph.networkx_graph, pos=node_pos, ax=ax)
edges_artist = nx.draw_networkx_edges(graph.networkx_graph, pos=node_pos, width=self.__edge_widths[num], edge_color=self.__edge_colors[num], ax=ax)
return nodes_artist, labels_artist, edges_artist
_ = animation.FuncAnimation(fig, _update, frames=len(self.__edge_colors), interval=self.__interval, repeat=self.__continuous)
plt.show()
示例10: plot_embedding2D
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def plot_embedding2D(node_pos, node_colors=None, di_graph=None, labels=None):
node_num, embedding_dimension = node_pos.shape
if(embedding_dimension > 2):
print("Embedding dimension greater than 2, use tSNE to reduce it to 2")
model = TSNE(n_components=2)
node_pos = model.fit_transform(node_pos)
if di_graph is None:
# plot using plt scatter
plt.scatter(node_pos[:, 0], node_pos[:, 1], c=node_colors)
else:
# plot using networkx with edge structure
pos = {}
for i in range(node_num):
pos[i] = node_pos[i, :]
if node_colors is not None:
nx.draw_networkx_nodes(di_graph, pos,
node_color=node_colors,
width=0.1, node_size=100,
arrows=False, alpha=0.8,
font_size=5, labels=labels)
else:
nx.draw_networkx(di_graph, pos, node_color=node_colors,
width=0.1, node_size=300, arrows=False,
alpha=0.8, font_size=12, labels=labels)
示例11: draw_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def draw_graph(self):
nx.draw_shell(self.G, with_labels=True, font_weight='bold')
# pos = graphviz_layout(self.G)
# plt.axis('off')
# nx.draw_networkx_nodes(self.G,pos,node_color='g',alpha = 0.8)
# nx.draw_networkx_edges(self.G,pos,edge_color='b',alpha = 0.6)
# nx.draw_networkx_edge_labels(self.G,pos,edge_labels = \
# nx.get_edge_attributes(self.G,'weight'))
# nx.draw_networkx_labels(self.G,pos) # node lables
plt.savefig('graph.png')
示例12: draw_adjacency_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [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::
示例13: malt_demo
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def malt_demo(nx=False):
"""
A demonstration of the result of reading a dependency
version of the first sentence of the Penn Treebank.
"""
dg = DependencyGraph("""Pierre NNP 2 NMOD
Vinken NNP 8 SUB
, , 2 P
61 CD 5 NMOD
years NNS 6 AMOD
old JJ 2 NMOD
, , 2 P
will MD 0 ROOT
join VB 8 VC
the DT 11 NMOD
board NN 9 OBJ
as IN 9 VMOD
a DT 15 NMOD
nonexecutive JJ 15 NMOD
director NN 12 PMOD
Nov. NNP 9 VMOD
29 CD 16 NMOD
. . 9 VMOD
""")
tree = dg.tree()
tree.pprint()
if nx:
# currently doesn't work
import networkx
from matplotlib import pylab
g = dg.nx_graph()
g.info()
pos = networkx.spring_layout(g, dim=1)
networkx.draw_networkx_nodes(g, pos, node_size=50)
# networkx.draw_networkx_edges(g, pos, edge_color='k', width=8)
networkx.draw_networkx_labels(g, pos, dg.nx_labels)
pylab.xticks([])
pylab.yticks([])
pylab.savefig('tree.png')
pylab.show()
示例14: plot
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def plot(cg):
"""
Plot the call graph using matplotlib
For larger graphs, this should not be used, as it is very slow
and probably you can not see anything on it.
:param cg: A networkx call graph to plot
"""
from androguard.core.analysis.analysis import ExternalMethod
import matplotlib.pyplot as plt
import networkx as nx
pos = nx.spring_layout(cg)
internal = []
external = []
for n in cg.node:
if isinstance(n, ExternalMethod):
external.append(n)
else:
internal.append(n)
nx.draw_networkx_nodes(cg, pos=pos, node_color='r', nodelist=internal)
nx.draw_networkx_nodes(cg, pos=pos, node_color='b', nodelist=external)
nx.draw_networkx_edges(cg, pos, arrow=True)
nx.draw_networkx_labels(cg, pos=pos,
labels={x: "{} {}".format(x.get_class_name(),
x.get_name())
for x in cg.edge})
plt.draw()
plt.show()
示例15: _draw_nodes
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_nodes [as 別名]
def _draw_nodes(self, nodelist, **kwargs):
node_color = kwargs.get('node_color', 'r')
if isinstance(node_color, dict):
node_color = [node_color[n] for n in nodelist]
kwargs['node_color'] = node_color
labels = kwargs.get('labels', {k: k for k in nodelist})
if labels is not False:
self._draw_node_labels(labels)
return nx.draw_networkx_nodes(self._G, self._pos, nodelist=nodelist, **kwargs)