12
12
from functools import lru_cache
13
13
from itertools import pairwise
14
14
from typing import Any
15
- from typing import List
16
- import numpy as np
17
15
18
16
import networkx as nx
19
17
import numpy as np
@@ -68,7 +66,6 @@ def collect_agent_data(
68
66
edgecolors_list = []
69
67
loc_list = []
70
68
71
-
72
69
for agent in space .agents :
73
70
portrayal = agent_portrayal (agent )
74
71
@@ -98,7 +95,9 @@ def collect_agent_data(
98
95
alpha = portrayal .get ("alpha" , 1.0 ),
99
96
linewidths = portrayal .get ("linewidths" , 1.0 ),
100
97
edgecolors = portrayal .get ("edgecolors" , "black" ),
101
- loc = agent .pos if hasattr (agent , "pos" ) else getattr (agent , "cell" , None ) and agent .cell .coordinate ,
98
+ loc = agent .pos
99
+ if hasattr (agent , "pos" )
100
+ else getattr (agent , "cell" , None ) and agent .cell .coordinate ,
102
101
)
103
102
104
103
color_list .append (portrayal .color )
@@ -123,7 +122,6 @@ def collect_agent_data(
123
122
}
124
123
125
124
126
-
127
125
def draw_space (
128
126
space ,
129
127
agent_portrayal : Callable ,
@@ -358,12 +356,9 @@ def draw_orthogonal_grid(
358
356
359
357
# gather agent data
360
358
s_default = (180 / max (space .width , space .height )) ** 2
361
-
362
- style = AgentPortrayalStyle ()
363
- arguments = collect_agent_data (
364
- space , agent_portrayal , style = style )
365
-
366
359
360
+ style = AgentPortrayalStyle ()
361
+ arguments = collect_agent_data (space , agent_portrayal , style = style )
367
362
368
363
# plot the agents
369
364
_scatter (ax , arguments , ** kwargs )
@@ -499,9 +494,17 @@ def draw_network(
499
494
else :
500
495
agent_style .loc = (0 , 0 ) # Fallback to (0,0) if node not found
501
496
502
-
503
497
# Pre-allocate all needed fields in one pass
504
- s , c , marker , zorder , loc , alpha , edgecolors , linewidths = [], [], [], [], [], [], [], []
498
+ s , c , marker , zorder , loc , alpha , edgecolors , linewidths = (
499
+ [],
500
+ [],
501
+ [],
502
+ [],
503
+ [],
504
+ [],
505
+ [],
506
+ [],
507
+ )
505
508
506
509
for a in agent_data_list :
507
510
s .append (a .size )
@@ -513,7 +516,6 @@ def draw_network(
513
516
edgecolors .append (a .edgecolors )
514
517
linewidths .append (a .linewidths )
515
518
516
-
517
519
# Convert data for plotting
518
520
scatter_data = {
519
521
"s" : [a .size for a in agent_data_list ],
@@ -687,7 +689,6 @@ def _scatter(ax: Axes, arguments, **kwargs):
687
689
linewidths .append (agent_data .linewidths )
688
690
alpha .append (agent_data .alpha )
689
691
690
-
691
692
# Check for edgecolor, linewidth, and alpha conflicts with kwargs
692
693
for entry , values in zip (
693
694
["edgecolors" , "linewidths" , "alpha" ], [edgecolors , linewidths , alpha ]
0 commit comments