Skip to content

Commit e39df00

Browse files
committed
simplify axes clearing
1 parent a53d8e8 commit e39df00

File tree

2 files changed

+1
-24
lines changed

2 files changed

+1
-24
lines changed

mesa/visualization/backends/matplotlib_backend.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def __init__(self, space_drawer):
4747
"""
4848
super().__init__(space_drawer)
4949

50-
self._active_colorbars = []
51-
5250
def initialize_canvas(self, ax=None):
5351
"""Initialize the matplotlib canvas.
5452
@@ -419,5 +417,4 @@ def draw_propertylayer(self, space, property_layers, propertylayer_portrayal):
419417
sm = ScalarMappable(norm=norm, cmap=cmap)
420418
sm.set_array([])
421419
cbar = plt.colorbar(sm, ax=self.ax, label=layer_name)
422-
self._active_colorbars.append(cbar)
423420
return self.ax, cbar

mesa/visualization/solara_viz.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -252,32 +252,12 @@ def SpaceRendererComponent(
252252

253253
if renderer.backend == "matplotlib":
254254
# Clear the previous plotted data and agents
255-
all_artists = [
256-
renderer.canvas.lines[:],
257-
renderer.canvas.collections[:],
258-
renderer.canvas.patches[:],
259-
renderer.canvas.images[:],
260-
renderer.canvas.artists[:],
261-
]
262-
263-
# Remove duplicate colorbars from the canvas
264-
for cbar in renderer.backend_renderer._active_colorbars:
265-
cbar.remove()
266-
renderer.backend_renderer._active_colorbars.clear()
267-
268-
# Chain them together into a single iterable
269-
for artist in itertools.chain.from_iterable(all_artists):
270-
artist.remove()
255+
renderer.canvas.clear()
271256

272-
# Draw the space structure if specified
273257
if renderer.space_mesh:
274258
renderer.draw_structure()
275-
276-
# Draw agents if specified
277259
if renderer.agent_mesh:
278260
renderer.draw_agents()
279-
280-
# Draw property layers if specified
281261
if renderer.propertylayer_mesh:
282262
renderer.draw_propertylayer()
283263

0 commit comments

Comments
 (0)