-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Property Layer Visualization Example AttributeError: 'space_kwargs' #3216
Copy link
Copy link
Closed
Description
Describe the bug
On this page, the following error is shown, and the resulting visualization does not work correctly, when run in Binder a blank property visualization shows, but the gini coefficient still displays
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[8], line 2
1 renderer = SpaceRenderer(model=money_model, backend="matplotlib")
----> 2 renderer.render(
3 space_kwargs={ # an alternative way to customize the grid structure
4 "lw": 2,
5 "ls": "solid",
6 "color": "black",
7 "alpha": 0.1,
8 },
9 agent_portrayal=agent_portrayal,
10 propertylayer_portrayal=propertylayer_portrayal,
11 )
File ~/checkouts/readthedocs.org/user_builds/mesa/envs/latest/lib/python3.14/site-packages/mesa/visualization/space_renderer.py:419, in SpaceRenderer.render(self, agent_portrayal, propertylayer_portrayal, **kwargs)
416 self.draw_space_kwargs.update(kwargs)
418 if self.space_mesh is None:
--> 419 self.draw_structure()
420 if self.agent_mesh is None and self.agent_portrayal is not None:
421 self.draw_agents()
File ~/checkouts/readthedocs.org/user_builds/mesa/envs/latest/lib/python3.14/site-packages/mesa/visualization/space_renderer.py:258, in SpaceRenderer.draw_structure(self, **kwargs)
250 warnings.warn(
251 "Passing kwargs to draw_structure() is deprecated. "
252 "Use setup_structure(**kwargs) before calling draw_structure().",
253 PendingDeprecationWarning,
254 stacklevel=2,
255 )
256 self.draw_space_kwargs.update(kwargs)
--> 258 self.space_mesh = self.backend_renderer.draw_structure(**self.draw_space_kwargs)
259 return self.space_mesh
File ~/checkouts/readthedocs.org/user_builds/mesa/envs/latest/lib/python3.14/site-packages/mesa/visualization/backends/matplotlib_backend.py:76, in MatplotlibBackend.draw_structure(self, **kwargs)
66 def draw_structure(self, **kwargs):
67 """Draw the space structure using matplotlib.
68
69 Args:
(...) 74 The matplotlib axes with the drawn structure.
75 """
---> 76 return self.space_drawer.draw_matplotlib(self.ax, **kwargs)
File ~/checkouts/readthedocs.org/user_builds/mesa/envs/latest/lib/python3.14/site-packages/mesa/visualization/space_drawers.py:120, in OrthogonalSpaceDrawer.draw_matplotlib(self, ax, **draw_space_kwargs)
118 # Draw grid lines
119 for x in np.arange(-0.5, self.space.width, 1):
--> 120 ax.axvline(x, **line_kwargs)
121 for y in np.arange(-0.5, self.space.height, 1):
122 ax.axhline(y, **line_kwargs)
File ~/checkouts/readthedocs.org/user_builds/mesa/envs/latest/lib/python3.14/site-packages/matplotlib/axes/_axes.py:891, in Axes.axvline(self, x, ymin, ymax, **kwargs)
888 scalex = (xx < xmin) or (xx > xmax)
890 trans = self.get_xaxis_transform(which='grid')
--> 891 l = mlines.Line2D([x, x], [ymin, ymax], transform=trans, **kwargs)
892 self.add_line(l)
893 l.get_path()._interpolation_steps = mpl.axis.GRIDLINE_INTERPOLATION_STEPS
File ~/checkouts/readthedocs.org/user_builds/mesa/envs/latest/lib/python3.14/site-packages/matplotlib/lines.py:421, in Line2D.__init__(self, xdata, ydata, linewidth, linestyle, color, gapcolor, marker, markersize, markeredgewidth, markeredgecolor, markerfacecolor, markerfacecoloralt, fillstyle, antialiased, dash_capstyle, solid_capstyle, dash_joinstyle, solid_joinstyle, pickradius, drawstyle, markevery, **kwargs)
417 self.set_markeredgewidth(markeredgewidth)
419 # update kwargs before updating data to give the caller a
420 # chance to init axes (and hence unit support)
--> 421 self._internal_update(kwargs)
422 self.pickradius = pickradius
423 self.ind_offset = 0
File ~/checkouts/readthedocs.org/user_builds/mesa/envs/latest/lib/python3.14/site-packages/matplotlib/artist.py:1233, in Artist._internal_update(self, kwargs)
1226 def _internal_update(self, kwargs):
1227 """
1228 Update artist properties without prenormalizing them, but generating
1229 errors as if calling `set`.
1230
1231 The lack of prenormalization is to maintain backcompatibility.
1232 """
-> 1233 return self._update_props(
1234 kwargs, "{cls.__name__}.set() got an unexpected keyword argument "
1235 "{prop_name!r}")
File ~/checkouts/readthedocs.org/user_builds/mesa/envs/latest/lib/python3.14/site-packages/matplotlib/artist.py:1206, in Artist._update_props(self, props, errfmt)
1204 func = getattr(self, f"set_{k}", None)
1205 if not callable(func):
-> 1206 raise AttributeError(
1207 errfmt.format(cls=type(self), prop_name=k),
1208 name=k)
1209 ret.append(func(v))
1210 if ret:
AttributeError: Line2D.set() got an unexpected keyword argument 'space_kwargs'
Expected behavior
Some sort of property layer visualization
To Reproduce
Go to https://mesa.readthedocs.io/latest/tutorials/7_visualization_propertylayer_visualization.html, click open in binder, run all cells.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels