Skip to content
Snippets Groups Projects
Commit 96d4439e authored by Andi Gerken's avatar Andi Gerken
Browse files

Added documentation for file plotting.

parent 3501fe5d
No related branches found
No related tags found
No related merge requests found
Pipeline #47028 passed
......@@ -43,3 +43,22 @@ Any attribute is allowed, but some cannonical attributes are prepared:<br>
## Properties
As described in `robofish.io`, all properties of `robofish.io.entity`s can be accessed by adding the prefix `entity_` to the function.
## Plotting
`robofish.io.file.File`s have a built in plotting tool with `robofish.io.file.File.plot()`.
With the option `lw_distances = True` the distance between two fish is represented throught the line width.
```python
import robofish.io
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1,2, figsize=(10,5))
f = robofish.io.File("...")
f.plot(ax=ax[0])
f.plot(ax=ax[1], lw_distances=True)
plt.show()
```
![](img/file_plot.png)
For all other options while plotting please check `robofish.io.file.File.plot()`.
docs/img/file_plot.png

290 KiB

......@@ -440,7 +440,9 @@ class File(h5py.File):
Array of names of the created entities
"""
assert poses.ndim == 3
assert (
poses.ndim == 3
), f"A 3 dimensional array was expected (entity, timestep, 3). There were {poses.ndim} dimensions in poses: {poses.shape}"
assert poses.shape[2] in [3, 4]
agents = poses.shape[0]
entity_names = []
......@@ -682,9 +684,26 @@ class File(h5py.File):
figsize=None,
step_size=4,
c=None,
cmap="Set1",
skip_timesteps=0,
max_timesteps=None,
):
"""Plot the file using matplotlib.pyplot
The tracks in the file are plotted using matplotlib.plot().
Args:
ax (matplotlib.axes, optional): An axes object to plot in. If None is given, a new figure is created.
lw_distances (bool, optional): Flag to show the distances between individuals through line width.
figsize (Tuple[int], optional): Size of a newly created figure.
step_size (int, optional): when using lw_distances, the track is split into sections which have a common line width. This parameter defines the length of the sections.
c (Array[color_representation], optional): An array of colors. Each item has to be matplotlib.colors.is_color_like(item).
cmap (matplotlib.colors.Colormap, optional): The colormap to use
skip_timesteps (int, optional): Skip timesteps in the begining of the file
max_timesteps (int, optional): Cut of timesteps in the end of the file.
Returns:
matplotlib.axes: The axes object with the plot.
"""
poses = self.entity_poses[:, :, :2]
if lw_distances and poses.shape[0] < 2:
......@@ -708,7 +727,7 @@ class File(h5py.File):
step_size = poses.shape[1]
line_width = 1
cmap = cm.get_cmap("Set1")
cmap = cm.get_cmap(cmap)
x_world, y_world = self.world_size
if figsize is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment