I know that I can convert a single graph to PDF using the command.
s = 'J~f[MN@PQg?'
g = Graph(s, sparse=True);
g.plot(layout="planar").save("g.pdf")
I want to highlight the edges of some graphs in red and then store them separately in a PDF with different pages.
s = 'J~f[MN@PQg?'
g = Graph(s, sparse=True);
g.plot(layout="planar")
g.delete_vertex(2)
H = graphs.CycleGraph(10)
L = { tuple(g.edges(labels=False,sort_vertices=True,sort=True)) for g in g.subgraph_search_iterator(H, induced=False) }
print(len(L))
cylce_lists = list(map(list, L))
def plot_with_highlight(G, highlight_edges):
"""
Plot the graph and highlight specified edges and their corresponding vertices.
Parameters:
G (Graph): The graph object to plot.
highlight_edges (list of tuples): The set of edges to highlight.
"""
# Extract vertices from the provided edges
highlight_vertices = list(set().union(*highlight_edges))
# Plot the graph and highlight the specified edges and vertices in red
plot(G,layout="planar", edge_colors={'red': highlight_edges}, vertex_colors={'red': highlight_vertices}).show()
for highlight_edges in cylce_lists:
plot_with_highlight(g, highlight_edges)
The ultimate goal is to print. It would be perfect if two images could be placed on each row of a single PDF.