@@ -271,8 +271,10 @@ def draw_orthogonal_grid(
271
271
272
272
# First draw cell colors if they exist
273
273
if hasattr (space , "all_cells" ): # Check if it's a cell space
274
- cell_colors = np .full ((space .height , space .width , 4 ), [1 , 1 , 1 , 0 ]) # Transparent default
275
-
274
+ cell_colors = np .full (
275
+ (space .height , space .width , 4 ), [1 , 1 , 1 , 0 ]
276
+ ) # Transparent default
277
+
276
278
for cell in space .all_cells :
277
279
if hasattr (cell , "color" ):
278
280
x , y = cell .coordinate
@@ -285,9 +287,9 @@ def draw_orthogonal_grid(
285
287
UserWarning ,
286
288
stacklevel = 2 ,
287
289
)
288
-
290
+
289
291
# Plot the cell colors
290
- ax .imshow (cell_colors , origin = ' lower' , interpolation = ' nearest' )
292
+ ax .imshow (cell_colors , origin = " lower" , interpolation = " nearest" )
291
293
292
294
# gather agent data
293
295
s_default = (180 / max (space .width , space .height )) ** 2
@@ -309,6 +311,7 @@ def draw_orthogonal_grid(
309
311
310
312
return ax
311
313
314
+
312
315
def draw_hex_grid (
313
316
space : HexGrid ,
314
317
agent_portrayal : Callable ,
@@ -338,20 +341,20 @@ def draw_hex_grid(
338
341
if hasattr (space , "all_cells" ):
339
342
patches = []
340
343
offset = math .sqrt (0.75 )
341
-
344
+
342
345
for cell in space .all_cells :
343
346
x , y = cell .coordinate
344
347
if y % 2 == 0 :
345
348
x += 0.5
346
349
y *= offset
347
-
350
+
348
351
hex_patch = RegularPolygon (
349
352
(x , y ),
350
353
numVertices = 6 ,
351
354
radius = math .sqrt (1 / 3 ),
352
355
orientation = np .radians (120 ),
353
356
)
354
-
357
+
355
358
if hasattr (cell , "color" ):
356
359
try :
357
360
hex_patch .set_facecolor (cell .color )
@@ -361,12 +364,12 @@ def draw_hex_grid(
361
364
UserWarning ,
362
365
stacklevel = 2 ,
363
366
)
364
- hex_patch .set_facecolor (' none' )
367
+ hex_patch .set_facecolor (" none" )
365
368
else :
366
- hex_patch .set_facecolor (' none' )
367
-
369
+ hex_patch .set_facecolor (" none" )
370
+
368
371
patches .append (hex_patch )
369
-
372
+
370
373
# Add colored hexagons
371
374
cell_collection = PatchCollection (patches , match_original = True )
372
375
ax .add_collection (cell_collection )
0 commit comments