Skip to content

Commit ee1f339

Browse files
wang-boyurht
authored andcommittedOct 11, 2024··
update matplotlib plot legend and xlabel
1 parent 80c1c42 commit ee1f339

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed
 

‎mesa/visualization/components/matplotlib.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def SpaceMatplotlib(
6363
elif space is None and propertylayer_portrayal:
6464
draw_property_layers(space_ax, space, propertylayer_portrayal, model)
6565

66-
solara.FigureMatplotlib(space_fig, format="png", dependencies=dependencies)
66+
solara.FigureMatplotlib(
67+
space_fig, format="png", bbox_inches="tight", dependencies=dependencies
68+
)
6769

6870

6971
def draw_property_layers(ax, space, propertylayer_portrayal, model):
@@ -327,11 +329,14 @@ def PlotMatplotlib(model, measure, dependencies: list[any] | None = None):
327329
elif isinstance(measure, dict):
328330
for m, color in measure.items():
329331
ax.plot(df.loc[:, m], label=m, color=color)
330-
fig.legend()
332+
ax.legend(loc="best")
331333
elif isinstance(measure, list | tuple):
332334
for m in measure:
333335
ax.plot(df.loc[:, m], label=m)
334-
fig.legend()
336+
ax.legend(loc="best")
337+
ax.set_xlabel("Step")
335338
# Set integer x axis
336339
ax.xaxis.set_major_locator(plt.MaxNLocator(integer=True))
337-
solara.FigureMatplotlib(fig, dependencies=dependencies)
340+
solara.FigureMatplotlib(
341+
fig, format="png", bbox_inches="tight", dependencies=dependencies
342+
)

0 commit comments

Comments
 (0)
Please sign in to comment.