Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Draw nodes
options = {
'marker': 'o',
's': 200,
'c': [0.85, 0.85, 1],
'facecolor': '0.5',
'lw': 0,
}
ax = plt.gca()
nodelist = list(g)
xy = numpy.asarray([pos[v] for v in nodelist])
node_collection = ax.scatter(xy[:, 0], xy[:, 1], **options)
node_collection.set_zorder(2)
# Draw edges
networkx.draw_networkx_edges(g, pos, arrows=False, edge_color='0.5')
# Draw labels
edge_labels = {(e[0], e[1]): e[2].get('label') for e in g.edges(data=True)}
networkx.draw_networkx_edge_labels(g, pos, edge_labels=edge_labels)
node_labels = {n[0]: n[1].get('label') for n in g.nodes(data=True)}
for key, label in node_labels.items():
if len(label) > 25:
parts = label.split(' ')
parts.insert(int(len(parts)/2), '\n')
label = ' '.join(parts)
node_labels[key] = label
networkx.draw_networkx_labels(g, pos, labels=node_labels)
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
plt.show()
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
shapes = dict.fromkeys(G.nodes(), 0.0)
for (u, v, d) in G.edges(data=True):
shapes[u] = 'o' if d['size'] > 1 else ''
# edge width, not in use at this moment
edgewidth = []
for (u, v, d) in G.edges(data = True):
edgewidth.append(2) #len(G.get_edge_data(u,v)))
parent_nodes_network = nx.draw_networkx_nodes(G, pos, nodelist = parent_nodes, node_shape = 'o', node_size = [sizes[i] for i in parent_nodes], node_color = '#EFEFEF')
final_nodes_network = nx.draw_networkx_nodes(G, pos, nodelist = final_nodes, node_shape = 'o', node_size = [sizes[i] for i in final_nodes], node_color = '#FAFFFA')
parent_nodes_network.set_edgecolor('#888888')
final_nodes_network.set_edgecolor('#88BB00')
nx.draw_networkx_edges(G, pos, alpha=0.4, node_size=10, width = 1, edge_color='#808080')
nx.draw_networkx_labels(G, pos, font_size=8, font_weight = 'bold', labels = dict([(u, '%s\n(%s)' % (d['label'], pretty_print(d['size']))) for u, v, d in G.edges(data=True)]))
# adjust the plot limits
xmax = 1.02 * max(x for x, y in list(pos.values()))
ymax = 1.02 * max(y for x, y in list(pos.values()))
plt.xlim(0, xmax)
plt.ylim(0, ymax)
plt.xticks([])
plt.yticks([])
plt.subplots_adjust(hspace = 0, wspace = 0, right = 0.995, left = 0.005, top = 0.995, bottom = 0.005)
plt.text(0.03, 0.97, title or "Topology", fontsize='xx-large',
fontname="Arial", fontweight="bold", transform=plt.gca().transAxes)
ax=plt.gca()
if v not in activated:
for u in activated:
if u in G[v]:
E.add_edge(u,v,weight=1)
activated.append(v)
pos = nx.spring_layout(E)
nx.draw_networkx_nodes(E, pos, node_color='k', node_size=10)
nx.draw_networkx_nodes(E, pos, T, node_color='b', node_size=300)
nx.draw_networkx_nodes(E, pos, S, node_color='w', node_size=300)
nx.draw_networkx_labels(E, pos, labels=dict(zip(T,T)), font_color='r', font_size=10, font_weight='extra bold')
nx.draw_networkx_edges(G, pos,edgelist=E.edges(), width=.5, edge_color='g', alpha=.5)
k = 0.9
iterations = 50
if parent_pos is not None and len(parent_pos) > 0:
pos = dict()
for k, v in parent_pos.items():
if k in graph.nodes():
pos[k] = v
fixed = list(pos.keys())
k = 0.1
iterations = 10
pos = nx.spring_layout(
graph, k=k, pos=pos, fixed=fixed, iterations=iterations)
nx.draw_networkx_nodes(
graph, pos, node_color=new_colors, node_size=200)
nx.draw_networkx_edges(
graph, pos, alpha=0.4, width=2.0, node_size=200, scale=1.0)
# Draw pattern edges highlighted
edgelist = [(instance[edge[0]], instance[edge[1]])
for edge in pattern.edges()]
nx.draw_networkx_edges(
graph, pos,
edgelist=edgelist,
width=3, alpha=0.3, edge_color=[instance_color] * len(edgelist), node_size=200)
min_y = min(
[v[1] for v in pos.values()])
max_y = max(
[v[1] for v in pos.values()])
labels = {}
pos = nx.spring_layout(G)
hard=[(u,v) for (u,v,d) in G.edges(data=True) if d['kind'] == "hard"]
soft=[(u,v) for (u,v,d) in G.edges(data=True) if d['kind'] == "soft"]
conn=[(u,v) for (u,v,d) in G.edges(data=True) if d['kind'] == "conn"]
remain = [i for i in G.nodes() if i!="paper"]
nx.draw_networkx_nodes(G,pos, nodelist=["paper"], node_color='orange',node_shape = 's', node_size=500, alpha=1)
nx.draw_networkx_nodes(G,pos, nodelist=remain, node_color='#167096',node_shape = 'o', node_size=100, alpha=1)
nx.draw_networkx_edges(G,pos,edgelist=hard,width=1)
nx.draw_networkx_edges(G,pos,edgelist=soft,width=1,alpha=0.5,style='dashed')
nx.draw_networkx_edges(G,pos,edgelist=conn,width=1,edge_color='black')
nx.draw_networkx_labels(G,pos,font_size=9,font_family='sans-serif')
import matplotlib.pyplot as plt
plt.axis('off')
plt.show()
# Determine a fine size for nodes
bbox = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
width, height = bbox.width, bbox.height
area = width * height * fig.dpi
n_nodes = len(g.nodes)
# size of node should be related to area and number of nodes -- heuristic
node_size = np.pi * area / n_nodes
node_r = np.sqrt(node_size / np.pi)
node_edge = node_r / 3
pos = nx.spring_layout(g)
nodes = nx.draw_networkx_nodes(g, node_size=node_size, pos=pos)
edges = nx.draw_networkx_edges(g, pos=pos)
nodes.set_edgecolor("w")
nodes.set_linewidth(node_edge)
plt.axis("square")
plt.axis("off")
return nodes
# (Optional) Add tour
if tour[0]==True:
# Get sequence of edges visited
path=[]
for i in range(len(tour[1])-1):
path.append((tour[1][i],tour[1][i+1]))
path.append((tour[1][len(tour[1])-1],tour[1][0]))
# Extend tour to non visited cities
non_visited_cities=[city for city in range(seq_length) if city not in tour[1]]
for city in non_visited_cities:
path.append((tour[1][0],city))
path.append((city,tour[1][0]))
nx.draw_networkx_edges(g,pos=pos,edgelist=path, width=2, edge_color='b')
plt.show()
for rxn in self.rxns], D=1)
G = nx.DiGraph()
G.add_nodes_from(spids, bipartite='sp')
G.add_nodes_from(rxnids, bipartite='rxn')
G.add_edges_from(edges)
node2color = OD(zip(spids, ['b']*len(spids))+zip(rxnids, ['g']*len(rxnids)))
ncolors = butil.get_values(node2color, G.nodes())
ecolors = ['r']*len(edges)
nlabels = OD(zip(G.nodes(), G.nodes()))
fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(111)
nx.draw_networkx(G, pos, ax=ax, node_color=ncolors, labels=nlabels)
nx.draw_networkx_edges(G, pos, ax=ax, edge_color=ecolors, width=3, arrows=arrows)
plt.savefig(filepath)
if show:
plt.show()
plt.close()
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