Graph Drawer¶
Module for graph drawing on a canvas in jupyter notebook.
- class pyrigi.graph_drawer.GraphDrawer(graph=None, size=(600, 600), layout_type='spring', place='all')[source]¶
Bases:
object
Class for graph drawing.
An instance of this class creates a canvas and takes mouse inputs in order to construct a graph. The vertices of the graph are labeled using non-negative integers.
Supported inputs are:
- Press mouse button on an empty place on canvas:
Add a vertex at the pointer position.
- Press mouse button on an existing vertex (or empty space) and
release the mouse button on another vertex (or empty space): Add/remove an edge between the two vertices.
- Drag a vertex with
Ctrl
being pressed: Reposition the vertex.
- Drag a vertex with
- Double-click on an existing vertex:
Remove the corresponding vertex.
- Double-click on an existing edge:
Remove the corresponding edge.
- Parameters:
graph (
Graph
) – A graph without loops which is to be drawn on canvas when the object is created. The non-integer labels are relabeledsize (
Sequence
[int
]) – Width and height of the canvas, defaults to[600,600]
. The width and height are adjusted so that they are multiples of 100 with minimum value 400 and maximum value 1000.layout_type (
str
) – Layout type to visualise thegraph
. For supported layout types seeGraph.layout()
. The default isspring
. Ifgraph
isNone
or empty, this parameter has no effect.place (
str
) – The part of the canvas that is used for drawinggraph
. Options areall
(default, use all canvas),E
(use the east part),W
(use the west part),N
(use the north part),S
(use the south part), and alsoNE
,NW
,SE
andSW
. Ifgraph
isNone
or empty, this parameter has no effect.
Examples
>>> from pyrigi import GraphDrawer >>> Drawer = GraphDrawer() HBox(children=(MultiCanvas(height=600, width=600)... >>> print(Drawer.graph()) Graph with vertices [] and edges []