Graph editor

sage.graphs.graph_editor.graph_editor(graph=None, graph_name=None, replace_input=True, **layout_options)

Opens a graph editor in the Sage notebook.


  • graph - a Graph instance (default: graphs.CompleteGraph(2)); the graph to edit

  • graph_name - a string (default: None); the variable name to use for the updated instance; by default, this function attempts to determine the name automatically

  • replace_input - a boolean (default: True); whether to replace the text in the input cell with the updated graph data when “Save” is clicked; if this is False, the data is still evaluated as if it had been entered in the cell


sage: g = graphs.CompleteGraph(3)
sage: graph_editor(g)                       # not tested
sage: graph_editor(graphs.HouseGraph())     # not tested
sage: graph_editor(graph_name='my_graph')   # not tested
sage: h = graphs.StarGraph(6)
sage: graph_editor(h, replace_input=False)  # not tested

Returns a string representation of a Graph instance usable by the graph_editor(). The encoded information is the number of vertices, their 2D positions, and a list of edges.



  • a string


sage: from sage.graphs.graph_editor import graph_to_js
sage: G = graphs.CompleteGraph(4)
sage: graph_to_js(G)
sage: graph_to_js(graphs.StarGraph(2))