Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return InteractiveClass(graph, node_labels=node_labels, edge_labels=edge_labels, **kwargs)
if __name__ == "__main__":
# create a figure for each possible combination of inputs
# TODO:
# - test node properties such as node_color, node_size, node_shape, etc.
arguments = OrderedDict(directed=(True, False),
strictly_positive=(True, False),
weighted=(True, False),
show_node_labels=(True,False),
show_edge_labels=(True, False),
test_format=('sparse', 'dense', 'networkx', 'igraph'),
InteractiveGraph=(None, InteractiveGraph))
combinations = itertools.product(*arguments.values())
for ii, combination in enumerate(combinations):
print(ii, zip(arguments.keys(), combination))
fig, ax = plt.subplots(1, 1, figsize=(16,16))
kwargs = dict(zip(arguments.keys(), combination))
graph = test(ax=ax, **kwargs)
title = ''.join(['{}: {}, '.format(key, value) for (key, value) in kwargs.items()])
filename = ''.join(['{}-{}_'.format(key, value) for (key, value) in kwargs.items()])
filename = filename[:-1] # remove trailing underscore
ax.set_title(title)
fig.savefig('../figures/{}.pdf'.format(filename))
plt.close()
def plot(title, **kwargs):
fig, ax = plt.subplots(1,1)
graph = netgraph.test(ax=ax, **kwargs)
fig.tight_layout()
fig.canvas.draw()
graph._update_view()
fig.savefig(FDIR + title.replace(' ', '_') + '.pdf')
fig.savefig(FDIR + title.replace(' ', '_') + '.svg')
plt.close()
radius=size,
numVertices=5,
facecolor=facecolor,
alpha=alpha,
linewidth=0.,
zorder=zorder)
elif shape == 'h': # hexagon
artist = RegularPolygon(xy=position,
radius=size,
numVertices=6,
facecolor=facecolor,
alpha=alpha,
linewidth=0.,
zorder=zorder)
elif shape == 8: # octagon
artist = RegularPolygon(xy=position,
radius=size,
numVertices=8,
facecolor=facecolor,
alpha=alpha,
linewidth=0.,
zorder=zorder)
else:
raise ValueError("Node shape one of: ''so^>v
facecolor=facecolor,
alpha=alpha,
orientation=0,
linewidth=0.,
zorder=zorder)
elif shape == '<': # triangle left
artist = RegularPolygon(xy=position,
radius=size,
numVertices=3,
facecolor=facecolor,
alpha=alpha,
orientation=np.pi*0.5,
linewidth=0.,
zorder=zorder)
elif shape == 'v': # triangle down
artist = RegularPolygon(xy=position,
radius=size,
numVertices=3,
facecolor=facecolor,
alpha=alpha,
orientation=np.pi,
linewidth=0.,
zorder=zorder)
elif shape == '>': # triangle right
artist = RegularPolygon(xy=position,
radius=size,
numVertices=3,
facecolor=facecolor,
alpha=alpha,
orientation=np.pi*1.5,
linewidth=0.,
zorder=zorder)
numVertices=4,
facecolor=facecolor,
alpha=alpha,
orientation=np.pi*0.5,
linewidth=0.,
zorder=zorder)
elif shape == 'p': # pentagon
artist = RegularPolygon(xy=position,
radius=size,
numVertices=5,
facecolor=facecolor,
alpha=alpha,
linewidth=0.,
zorder=zorder)
elif shape == 'h': # hexagon
artist = RegularPolygon(xy=position,
radius=size,
numVertices=6,
facecolor=facecolor,
alpha=alpha,
linewidth=0.,
zorder=zorder)
elif shape == 8: # octagon
artist = RegularPolygon(xy=position,
radius=size,
numVertices=8,
facecolor=facecolor,
alpha=alpha,
linewidth=0.,
zorder=zorder)
else:
raise ValueError("Node shape one of: ''so^>v
radius=size,
facecolor=facecolor,
alpha=alpha,
linewidth=0.,
zorder=zorder)
elif shape == '^': # triangle up
artist = RegularPolygon(xy=position,
radius=size,
numVertices=3,
facecolor=facecolor,
alpha=alpha,
orientation=0,
linewidth=0.,
zorder=zorder)
elif shape == '<': # triangle left
artist = RegularPolygon(xy=position,
radius=size,
numVertices=3,
facecolor=facecolor,
alpha=alpha,
orientation=np.pi*0.5,
linewidth=0.,
zorder=zorder)
elif shape == 'v': # triangle down
artist = RegularPolygon(xy=position,
radius=size,
numVertices=3,
facecolor=facecolor,
alpha=alpha,
orientation=np.pi,
linewidth=0.,
zorder=zorder)
facecolor=facecolor,
alpha=alpha,
orientation=np.pi,
linewidth=0.,
zorder=zorder)
elif shape == '>': # triangle right
artist = RegularPolygon(xy=position,
radius=size,
numVertices=3,
facecolor=facecolor,
alpha=alpha,
orientation=np.pi*1.5,
linewidth=0.,
zorder=zorder)
elif shape == 's': # square
artist = RegularPolygon(xy=position,
radius=size,
numVertices=4,
facecolor=facecolor,
alpha=alpha,
orientation=np.pi*0.25,
linewidth=0.,
zorder=zorder)
elif shape == 'd': # diamond
artist = RegularPolygon(xy=position,
radius=size,
numVertices=4,
facecolor=facecolor,
alpha=alpha,
orientation=np.pi*0.5,
linewidth=0.,
zorder=zorder)
facecolor=facecolor,
alpha=alpha,
orientation=np.pi*0.25,
linewidth=0.,
zorder=zorder)
elif shape == 'd': # diamond
artist = RegularPolygon(xy=position,
radius=size,
numVertices=4,
facecolor=facecolor,
alpha=alpha,
orientation=np.pi*0.5,
linewidth=0.,
zorder=zorder)
elif shape == 'p': # pentagon
artist = RegularPolygon(xy=position,
radius=size,
numVertices=5,
facecolor=facecolor,
alpha=alpha,
linewidth=0.,
zorder=zorder)
elif shape == 'h': # hexagon
artist = RegularPolygon(xy=position,
radius=size,
numVertices=6,
facecolor=facecolor,
alpha=alpha,
linewidth=0.,
zorder=zorder)
elif shape == 8: # octagon
artist = RegularPolygon(xy=position,
def _get_tile_positions(self):
# find tiles through which a each edge crosses using the line supercover
# (an extension of Bresenheims algorithm)
tile_positions = []
for (v0, v1) in self.edge_list:
x0, y0 = self.node_positions[v0]
x1, y1 = self.node_positions[v1]
x0 = np.int(np.round(x0))
y0 = np.int(np.round(y0))
x1 = np.int(np.round(x1))
y1 = np.int(np.round(y1))
x, y = line_supercover(x0, y0, x1, y1)
tile_positions.extend(zip(x.tolist(), y.tolist()))
# remove duplicates
tile_positions = list(set(tile_positions))
return tile_positions
shape = 'right'
else:
shape = 'full'
if draw_arrows:
offset = node_size[target]
head_length = 2 * width
head_width = 3 * width
length_includes_head = True
else:
offset = None
head_length = 1e-10 # 0 throws error
head_width = 1e-10 # 0 throws error
length_includes_head = False
patch = FancyArrow(x1, y1, dx, dy,
width=width,
facecolor=color,
alpha=alpha,
head_length=head_length,
head_width=head_width,
length_includes_head=length_includes_head,
zorder=1,
edgecolor='none',
linewidth=0.1,
offset=offset,
shape=shape)
ax.add_artist(patch)
artists[(source, target)] = patch
else: # source == target, i.e. a self-loop
import warnings