File tree 1 file changed +18
-1
lines changed
1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 1
1
import threading
2
2
3
3
import matplotlib .pyplot as plt
4
+ import networkx as nx
4
5
import reacton .ipywidgets as widgets
5
6
import solara
6
7
from matplotlib .figure import Figure
7
8
from matplotlib .ticker import MaxNLocator
8
9
10
+ import mesa
11
+
9
12
# Avoid interactive backend
10
13
plt .switch_backend ("agg" )
11
14
@@ -91,10 +94,24 @@ def portray(self, g):
91
94
return out
92
95
93
96
97
+ def _draw_network_grid (viz , space_ax ):
98
+ graph = viz .model .grid .G
99
+ pos = nx .spring_layout (graph , seed = 0 )
100
+ nx .draw (
101
+ graph ,
102
+ ax = space_ax ,
103
+ pos = pos ,
104
+ ** viz .agent_portrayal (graph ),
105
+ )
106
+
107
+
94
108
def make_space (viz ):
95
109
space_fig = Figure ()
96
110
space_ax = space_fig .subplots ()
97
- space_ax .scatter (** viz .portray (viz .model .grid ))
111
+ if isinstance (viz .model .grid , mesa .space .NetworkGrid ):
112
+ _draw_network_grid (viz , space_ax )
113
+ else :
114
+ space_ax .scatter (** viz .portray (viz .model .grid ))
98
115
space_ax .set_axis_off ()
99
116
solara .FigureMatplotlib (space_fig , dependencies = [viz .model , viz .df ])
100
117
You can’t perform that action at this time.
0 commit comments