dwave-networkx
dwave-networkx copied to clipboard
Column Graph Layout
The documentation shows an example of the column graph layout, but is it available in the package?
Not yet, but I will consider this a feature request!
Any update on this? It's much easier for me to visualize the column graph layout over the cross layout and it is the typical representation seen nowadays (from my experience).
Here's a proof of concept. It will be a piece of work to get this integrated into the other drawing functions, but this should ease the process.
from matplotlib import patches, collections, path
from random import randint
from itertools import repeat
def draw_columnar(g, edge_colors = None):
ax = plt.gca()
rows, cols, tile = g.graph['rows'], g.graph['columns'], g.graph['tile']
coord = dnx.chimera_coordinates(rows, cols, tile).linear_to_chimera
coords = {v: coord(v) for v in g}
width = tile
pos = {v: (width*(x + u/2), (tile+1)*y + k)
for v, (y, x, u, k) in coords.items()}
internal = []
icolor = []
external = []
ecolor = []
if edge_colors is None:
edge_colors = repeat('black')
for (u, v), c in zip(g.edges(), edge_colors):
if coords[u][:2] == coords[v][:2]:
internal.append((pos[u], pos[v]))
icolor.append(c)
else:
external.append(patches.FancyArrowPatch(
pos[min(u,v)], pos[max(u,v)],
arrowstyle='-',
patchA = None, patchB = None,
shrinkA=50, shrinkB=50,
connectionstyle='arc3,rad=-0.2',
))
ecolor.append(c)
ax.add_collection(collections.LineCollection(internal,
edgecolor=icolor))
ax.add_collection(collections.PatchCollection(external,
facecolor='none', edgecolor=ecolor))
nx.draw_networkx_nodes(g, pos)
if __name__ == "__main__":
plt.figure(figsize=(20,20))
draw_columnar(dnx.chimera_graph(6))
plt.savefig('foo.png')
plt.close()
