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

Conversation

wang-boyu
Copy link
Member

  • change matplotlib plot format from "png" to "svg"
  • automatically set legend location through ax.legend(loc="best")
  • add text "Step" to x axis label

Before:

before

After:

after

@wang-boyu wang-boyu added the enhancement Release notes label label Oct 10, 2024
Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +0.4% [-0.4%, +1.2%] 🔵 +0.3% [+0.2%, +0.5%]
BoltzmannWealth large 🔵 -0.9% [-1.4%, -0.5%] 🔵 -1.7% [-2.8%, -0.7%]
Schelling small 🔵 -0.2% [-0.4%, +0.1%] 🔵 +0.2% [-0.1%, +0.4%]
Schelling large 🔵 +0.1% [-0.7%, +1.0%] 🔵 +1.6% [-0.5%, +3.9%]
WolfSheep small 🔵 -0.8% [-1.1%, -0.6%] 🔵 -0.3% [-0.5%, -0.0%]
WolfSheep large 🔵 -2.2% [-3.2%, -1.0%] 🔵 -4.4% [-6.0%, -2.6%]
BoidFlockers small 🔵 -2.7% [-3.1%, -2.3%] 🔵 -1.5% [-2.2%, -0.8%]
BoidFlockers large 🔵 -3.3% [-3.9%, -2.6%] 🔵 -1.5% [-2.3%, -0.8%]

Copy link
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All obviously good changes!

One question, are there any implications for performance? Is exporting to SVG slower (or faster) than to PNG?

Otherwise, go ahead and merge.

@@ -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="svg", bbox_inches="tight", dependencies=dependencies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using png is intentional: #1806 (comment). At the very least, a comment should be added to say it is for performance reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes svg is indeed very low as compare to png: solara-perf.ipynb (863 ms for png vs. 3.89 s for svg, for a 200x200 schelling model). I also tried increasing png dpi from default 100 to 300, and it becomes slower with no noticeable improvement in terms of plot quality. I have changed back to png format in this PR.

@rht rht merged commit ee1f339 into projectmesa:main Oct 11, 2024
10 of 12 checks passed
@wang-boyu wang-boyu deleted the viz/plot-matplotlib branch October 11, 2024 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Release notes label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants