Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to store images in a PDF?

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.

How to store images in a PDF?

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 I got six figures. My goal is to print. It would be perfect if two images could be placed on each row of a single PDF.

How to store images in a PDF?

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)

I got six figures. My goal is to print. It would be perfect if two images could be placed on each row of a single PDF.

How to store images of graphs in a PDF?

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)

I got six figures. My goal is to print. It would be perfect if two images could be placed on each row of a single PDF.

How to store images of graphs in a PDF?

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)

I got six figures. My goal is to print. It would be perfect if two images could be placed on each row of a single PDF.

How to store images of graphs in a PDF?

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.plot(layout="planar",save_pos=True)
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):
    highlight_vertices = list(set().union(*highlight_edges))
    plot(G,layout="planar", plot(G, edge_colors={'red': highlight_edges}, vertex_colors={'red': highlight_vertices}).show()
for highlight_edges in cylce_lists:
    plot_with_highlight(g, highlight_edges)

I got six figures. My goal is to print. It would be perfect if two images could be placed on each row of a single PDF.