visualizer package¶
Submodules¶
visualizer.plot module¶
- visualizer.plot.plot_organisms(step, organisms, grid_size=20, output_dir='frames', foodweb=None, terrain=None)[source]¶
Plots the state of the simulation at a given step.
This function visualizes the environment and all organisms present at the specified step. It overlays terrain types and animal positions using colored markers. If multiple organisms are at the same position, they are slightly offset to be visible. Dead organisms are marked with ‘x’.
- Parameters:
step (int) – The simulation step number.
organisms (list) – List of organism objects with species, coordinates, and alive status.
grid_size (int) – Size of the simulation grid (default is 20).
output_dir (str) – Directory to save the output PNG (default is “frames”).
foodweb (object) – Optional foodweb object to map species to consistent colors.
terrain (object) – Optional terrain object to render environmental backgrounds.
- visualizer.plot.get_species_colors(organisms, foodweb=None)[source]¶
Assigns consistent colors to each species based on the foodweb or automatically.
If a foodweb object is provided, species colors are fetched using its color mapping. Otherwise, a default colormap (‘tab10’) is used to assign distinguishable colors.
- Parameters:
organisms (list) – List of organism objects containing a .species attribute.
foodweb (object, optional) – Object with a get_color(species) method.
- Returns:
Mapping from species name to hex color code.
- Return type:
dict[str, str]
- visualizer.plot.create_animation(frame_folder: str = 'frames', output_path: str = 'statistics_plots/animation.gif', fps: int = 4, frame_range: Optional[tuple[int, int]] = None) None[source]¶
Creates an animated GIF from PNG frame images in the given folder.
- Parameters:
frame_folder – Directory containing .png frames
output_path – Where to save the animation
fps – Frames per second
frame_range – Tuple (start, end) to limit frames, or None for all
- visualizer.plot.compose_frames_side_by_side(frame_indices: list[int], frame_folder: str = 'frames', output_path: str = 'statistics_plots/frames_side_by_side.png') None[source]¶
Composes selected PNG frames side-by-side into a single image.
- Parameters:
frame_indices – List of frame numbers (e.g. [0, 5, 10])
frame_folder – Directory containing frame PNGs
output_path – Output PNG file path