Skip to content

Commit

Permalink
Merge pull request #7 from MHenderson/6-improve-visualisations
Browse files Browse the repository at this point in the history
Improve visualisations
  • Loading branch information
MHenderson authored Nov 27, 2024
2 parents a06cd12 + d9ea082 commit b36ccd4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
Binary file modified png/petersen-edge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified png/petersen-node.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions src/petersen-edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
edge_colours = nx.get_edge_attributes(G,'colour').values()

nx.draw(G,
pos = G_layout,
edge_color = edge_colours,
pos = G_layout,
edge_color = edge_colours,
with_labels = False,
edge_cmap = plt.cm.tab10,
width = 5,
node_size = 150,
node_color = 'black')
edge_cmap = plt.cm.tab10,
width = 5,
node_size = 150,
node_color = 'black')

edge_labels = dict([((n1, n2), str(d['colour']) + ': ' + str(sorted(d['permissible']))) for n1, n2, d in G.edges(data = True)])
edge_labels = dict([((n1, n2), str(sorted(d['permissible']))) for n1, n2, d in G.edges(data = True)])
X = nx.draw_networkx_edge_labels(G, pos = G_layout, edge_labels = edge_labels, font_size = 6)

patches = [mpatches.Patch(color = plt.cm.tab10(i), label = f'{i}') for i in edge_colours]
plt.legend(handles = patches, title = "Colours", bbox_to_anchor = (1, 1))
patches = [mpatches.Patch(color = plt.cm.tab10(i), label = f'{i}') for i in range(10)]
plt.legend(handles = patches, bbox_to_anchor = (1, 1))

plt.savefig("png/petersen-edge.png", format = "PNG")
24 changes: 11 additions & 13 deletions src/petersen-node.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,28 @@
import vizing as vz

G = nx.petersen_graph()
G = lc.list_init_node(G, range(1, 10), 3, 0)
G = lc.list_init_node(G, range(0, 10), 3, 0)
G = vz.node_list_colouring_solution(G)

G_layout = nx.shell_layout(G, nlist = [range(5, 10), range(5)], rotate = 0.)

node_labels = dict([(n, str(d['colour']) + ': ' + str(d['permissible'])) for n, d in G.nodes(data = True)])
node_labels = dict([(n, str(sorted(d['permissible']))) for n, d in G.nodes(data = True)])

node_colors = set(nx.get_node_attributes(G, 'colour').values())

patches = [mpatches.Patch(color = plt.cm.tab10(i), label = f'{i}') for i in node_colors]

nx.draw(G,
G_layout,
edge_color = "black",
node_color = list(nx.get_node_attributes(G, 'colour').values()),
node_shape = 's',
width = 10,
node_size = 1300,
cmap = plt.cm.tab10,
labels = node_labels,
font_size = 6,
edge_color = "black",
node_color = list(nx.get_node_attributes(G, 'colour').values()),
width = 4,
node_size = 1000,
cmap = plt.cm.tab10,
labels = node_labels,
font_size = 6,
with_labels = True
)

plt.legend(handles = patches, title = "Colours", bbox_to_anchor = (1, 1))
patches = [mpatches.Patch(color = plt.cm.tab10(i), label = f'{i}') for i in range(1, 10)]
plt.legend(handles = patches, bbox_to_anchor = (1, 1))

plt.savefig("png/petersen-node.png", format = "PNG")

0 comments on commit b36ccd4

Please sign in to comment.