0

I would like to plot a graph where two of the nodes have fixed coordinates, and the rest are determined using an automatic layout by igraph. The goal is to create an animation in which, in every frame, the location of two nodes is kept constant, and the rest of the nodes are spread as far apart as possible (by the automatic python igraph layout algorithm). Any ideas?

I tried:

    current_graph = graphs[frame]

    automatic_layout = current_graph.layout("kk")

    coords = np.array(automatic_layout.coords)
    

    env_x = coords[:, 0].min() - padding_x  #(defined elsewhere)
    env_y = coords[:, 1].max() + env_bump_y + padding_y  #(defined elsewhere)
                          
    seed_x = env_x
    seed_y = 0
                          
                          
    fixed_layout = [[env_x, env_y] if (node['id'] == 'Env') else [seed_x, seed_y] if (node['id'] == seed_cell_id) else None for node in current_graph.vs]

    
    # Combine the fixed and automatic layouts
    combined_layout = [coords if coords is not None else automatic_layout[node] for node, coords in enumerate(fixed_layout)]

However, because I am simply substituting my fixed coordinates into the automatic layout, there are sometimes overlap between my fixed coordinates and the coordinates generated by the automatic layout.

  • 1
    `layout_kamada_kawai()` and `layout_fruchterman_reingold()` have the minx/maxx, miny/maxy arguments which allow constraining each vertex into a bounding box. Use size zero boxes to fix your two vertices, and infinite boxes for the rest. – Szabolcs Jun 28 '23 at 08:11

0 Answers0