Skip to content

Commit 411386e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2d6eca1 commit 411386e

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

mesa/visualization/components/matplotlib_components.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
from matplotlib.figure import Figure
1111

1212
from mesa.visualization.AgentPortrayalStyle import AgentPortrayalStyle
13-
from mesa.visualization.mpl_space_drawing import draw_space
13+
from mesa.visualization.mpl_space_drawing import collect_agent_data, draw_space
1414
from mesa.visualization.utils import update_counter
15-
from mesa.visualization.mpl_space_drawing import collect_agent_data
1615

1716

1817
def make_space_matplotlib(*args, **kwargs): # noqa: D103
@@ -31,8 +30,8 @@ def make_mpl_space_component(
3130
**space_drawing_kwargs,
3231
) -> Callable:
3332
"""Create a Matplotlib-based space visualization component."""
34-
3533
if agent_portrayal is None:
34+
3635
def agent_portrayal(a):
3736
return AgentPortrayalStyle()
3837

@@ -48,7 +47,6 @@ def MakeSpaceMatplotlib(model):
4847
return MakeSpaceMatplotlib # <-- Fix: Return the function
4948

5049

51-
5250
@solara.component
5351
def SpaceMatplotlib(
5452
model,

mesa/visualization/mpl_space_drawing.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
from functools import lru_cache
1313
from itertools import pairwise
1414
from typing import Any
15-
from typing import List
16-
import numpy as np
1715

1816
import networkx as nx
1917
import numpy as np
@@ -68,7 +66,6 @@ def collect_agent_data(
6866
edgecolors_list = []
6967
loc_list = []
7068

71-
7269
for agent in space.agents:
7370
portrayal = agent_portrayal(agent)
7471

@@ -98,7 +95,9 @@ def collect_agent_data(
9895
alpha=portrayal.get("alpha", 1.0),
9996
linewidths=portrayal.get("linewidths", 1.0),
10097
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,
102101
)
103102

104103
color_list.append(portrayal.color)
@@ -123,7 +122,6 @@ def collect_agent_data(
123122
}
124123

125124

126-
127125
def draw_space(
128126
space,
129127
agent_portrayal: Callable,
@@ -358,12 +356,9 @@ def draw_orthogonal_grid(
358356

359357
# gather agent data
360358
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-
366359

360+
style = AgentPortrayalStyle()
361+
arguments = collect_agent_data(space, agent_portrayal, style=style)
367362

368363
# plot the agents
369364
_scatter(ax, arguments, **kwargs)
@@ -499,9 +494,17 @@ def draw_network(
499494
else:
500495
agent_style.loc = (0, 0) # Fallback to (0,0) if node not found
501496

502-
503497
# 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+
)
505508

506509
for a in agent_data_list:
507510
s.append(a.size)
@@ -513,7 +516,6 @@ def draw_network(
513516
edgecolors.append(a.edgecolors)
514517
linewidths.append(a.linewidths)
515518

516-
517519
# Convert data for plotting
518520
scatter_data = {
519521
"s": [a.size for a in agent_data_list],
@@ -687,7 +689,6 @@ def _scatter(ax: Axes, arguments, **kwargs):
687689
linewidths.append(agent_data.linewidths)
688690
alpha.append(agent_data.alpha)
689691

690-
691692
# Check for edgecolor, linewidth, and alpha conflicts with kwargs
692693
for entry, values in zip(
693694
["edgecolors", "linewidths", "alpha"], [edgecolors, linewidths, alpha]

0 commit comments

Comments
 (0)