Skip to content

Commit

Permalink
update matplotlib plot legend and xlabel
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-boyu committed Oct 11, 2024
1 parent 2cdbcb6 commit 37a23b7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mesa/visualization/components/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def SpaceMatplotlib(
elif space is None and propertylayer_portrayal:
draw_property_layers(space_ax, space, propertylayer_portrayal, model)

solara.FigureMatplotlib(space_fig, format="png", dependencies=dependencies)
solara.FigureMatplotlib(
space_fig, format="png", bbox_inches="tight", dependencies=dependencies
)


def draw_property_layers(ax, space, propertylayer_portrayal, model):
Expand Down Expand Up @@ -327,11 +329,14 @@ def PlotMatplotlib(model, measure, dependencies: list[any] | None = None):
elif isinstance(measure, dict):
for m, color in measure.items():
ax.plot(df.loc[:, m], label=m, color=color)
fig.legend()
ax.legend(loc="best")

Check warning on line 332 in mesa/visualization/components/matplotlib.py

View check run for this annotation

Codecov / codecov/patch

mesa/visualization/components/matplotlib.py#L332

Added line #L332 was not covered by tests
elif isinstance(measure, list | tuple):
for m in measure:
ax.plot(df.loc[:, m], label=m)
fig.legend()
ax.legend(loc="best")
ax.set_xlabel("Step")

Check warning on line 337 in mesa/visualization/components/matplotlib.py

View check run for this annotation

Codecov / codecov/patch

mesa/visualization/components/matplotlib.py#L336-L337

Added lines #L336 - L337 were not covered by tests
# Set integer x axis
ax.xaxis.set_major_locator(plt.MaxNLocator(integer=True))
solara.FigureMatplotlib(fig, dependencies=dependencies)
solara.FigureMatplotlib(

Check warning on line 340 in mesa/visualization/components/matplotlib.py

View check run for this annotation

Codecov / codecov/patch

mesa/visualization/components/matplotlib.py#L340

Added line #L340 was not covered by tests
fig, format="png", bbox_inches="tight", dependencies=dependencies
)

0 comments on commit 37a23b7

Please sign in to comment.