Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update legend, xlabel & format of matplotlib plots #2346

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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")
EwoutH marked this conversation as resolved.
Show resolved Hide resolved
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
)
Loading