-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmind_map_visualizer.py
29 lines (24 loc) · 1011 Bytes
/
mind_map_visualizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import matplotlib.pyplot as plt
import networkx as nx
from logger import log_function_call
from pip._vendor.rich.logging import RichHandler
class MindMapVisualizer:
def __init__(self, logger):
self.logger = logger
@log_function_call(RichHandler())
def visualize_mind_map(self, graph, start_topic, fig=None):
self.logger.info("Visualizing mind map")
if fig is None:
fig, ax = plt.subplots(figsize=(12, 8))
else:
fig.clear()
ax = fig.add_subplot(111)
pos = nx.spring_layout(graph)
nx.draw(graph, pos, ax=ax, with_labels=True, node_color='lightblue',
node_size=3000, font_size=8, font_weight='bold')
ax.set_title(f"Mind Map for '{start_topic}'")
ax.axis('off')
# Instead of tight_layout, adjust the figure size if needed
fig.set_size_inches(12, 8)
fig.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
return fig