-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6991a03
commit 8e6e3f9
Showing
7 changed files
with
35 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# mypy: ignore-errors | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
# mypy: ignore-errors | ||
import matplotlib.pyplot as plt | ||
from matplotlib.animation import FuncAnimation | ||
|
||
from vivarium import InteractiveContext | ||
|
||
def plot_boids(simulation, plot_velocity=False): | ||
|
||
def plot_boids(simulation: InteractiveContext, plot_velocity: bool=False) -> None: | ||
width = simulation.configuration.field.width | ||
height = simulation.configuration.field.height | ||
pop = simulation.get_population() | ||
|
||
plt.figure(figsize=[12, 12]) | ||
plt.figure(figsize=(12, 12)) | ||
plt.scatter(pop.x, pop.y, color=pop.color) | ||
if plot_velocity: | ||
plt.quiver(pop.x, pop.y, pop.vx, pop.vy, color=pop.color, width=0.002) | ||
plt.xlabel("x") | ||
plt.ylabel("y") | ||
plt.axis([0, width, 0, height]) | ||
plt.axis((0, width, 0, height)) | ||
plt.show() | ||
|
||
|
||
def plot_boids_animated(simulation): | ||
def plot_boids_animated(simulation: InteractiveContext) -> FuncAnimation: | ||
width = simulation.configuration.field.width | ||
height = simulation.configuration.field.height | ||
pop = simulation.get_population() | ||
|
||
fig = plt.figure(figsize=[12, 12]) | ||
fig = plt.figure(figsize=(12, 12)) | ||
ax = fig.add_subplot(111) | ||
s = ax.scatter(pop.x, pop.y, color=pop.color) | ||
plt.xlabel("x") | ||
plt.ylabel("y") | ||
plt.axis([0, width, 0, height]) | ||
plt.axis((0, width, 0, height)) | ||
|
||
frames = range(2_000) | ||
frame_pops = [] | ||
for _ in frames: | ||
simulation.step() | ||
frame_pops.append(simulation.get_population()[["x", "y"]]) | ||
|
||
def animate(i): | ||
def animate(i: int) -> None: | ||
s.set_offsets(frame_pops[i]) | ||
|
||
return FuncAnimation(fig, animate, frames=frames, interval=10) | ||
return FuncAnimation(fig, animate, frames=frames, interval=10) # type: ignore[arg-type] |