Base Class
Draw
Base class for drawing various data structures.Methods
set_figsize
Sets the figure size for the plot.Tuple representing the figure size (width, height)
save
Saves the rendered plot to a file.Name of the file to save the plot to
Additional keyword arguments for customization
draw
Displays the rendered plot.Additional keyword arguments for customization
TreeDraw
Class for drawing binary tree structures.The tree structure to be drawn
Methods
add_edges
Recursively adds edges to the graph and positions nodes in a tree layout.The graph object where edges are added
The current node in the tree
Dictionary to store node positions
X-coordinate for the current node
Y-coordinate for the current node
Current layer/level of the node in the tree
Dictionary containing positions of all nodes in the tree
HeapDraw
Class for drawing heap structures.The heap structure to be drawn
Methods
array_to_node
Converts an array-based heap into a tree node structure.Current index in the array representing the node
Array containing heap values
Root node of the constructed subtree
TrieDraw
Class for drawing trie structures.The trie structure to be drawn
Methods
to_networkx
Converts the trie into a NetworkX directed graph.NetworkX graph representation of the trie
hierarchical_pos
Computes hierarchical positions for nodes in the graph.The graph for which to compute positions
Root node of the graph (auto-determined if None)
Width of the entire drawing
Gap between levels in the hierarchy
Vertical location of the root node
Horizontal center of the root node
Dictionary mapping each node to its (x, y) position
GraphDraw
Class for drawing graphs (both directed and undirected, weighted and unweighted).The graph to be drawn (any graph type: AdjacencyMatrixGraph, AdjacencyListGraph, etc.)
Specifies if the graph is directed (inferred from graph if None)
Specifies if the graph has weighted edges (inferred from graph if None)
Methods
render
Renders the graph using Matplotlib.Node positions dictionary (auto-computed if None)
If True, highlights the minimum spanning tree in red
If True, shows only the MST edges
Additional keyword arguments
Matplotlib plot object
Visualization Tips
Visualization Tips
Choosing Figure Size:
- Small structures (< 10 nodes):
(5, 3)or(6, 4) - Medium structures (10-50 nodes):
(10, 6)or(12, 8) - Large structures (> 50 nodes):
(15, 10)or larger
- Default layout is
shell_layoutfor graphs - For hierarchical structures (trees, heaps, tries), custom hierarchical positioning is used
- Use
show_mst=Trueto overlay MST edges in red on the full graph - Use
mst_only=Trueto show only the MST edges - MST is computed using NetworkX’s minimum spanning tree algorithm
draw()displays the plot interactivelysave()writes the plot to a file without displaying- Both methods accept the same kwargs for customization