Skip to content

Commit

Permalink
Make figure sizes decent
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmig committed Dec 2, 2024
1 parent 5428ffe commit 4b7f339
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions examples/load_and_reindex_bboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# %matplotlib widget
import csv
import math
import os

import sleap_io as sio
from matplotlib import pyplot as plt
Expand All @@ -26,7 +27,8 @@
# Load sample dataset
# ------------------------
# In this tutorial, we will use a sample bounding boxes dataset with
# a single individual (a crab).
# a single individual (a crab). The clip is part of the `Moving
# Camouflaged Animals Dataset (MoCA) dataset <https://www.robots.ox.ac.uk/~vgg/data/MoCA/>`_.
#
# We will also download the associated video for visualising the data later.

Expand All @@ -49,11 +51,11 @@

# %%
# We can see the coordinates in the time dimension are expressed in frames,
# and that only 1 in 5 frames of the video are annotated, plus
# and that we only have data for 1 in 5 frames of the video, plus
# the last frame (167).
#
# In the following sections of the notebook we will explore options to reindex
# the dataset, and fill in the missing frames with reasonable values.
# the dataset and fill in values for the frames with missing data.
print(ds.time)

# %%
Expand Down Expand Up @@ -87,15 +89,15 @@
data_end_idx = 15

# initialise figure
fig = plt.figure(figsize=(15, 12))
fig = plt.figure(figsize=(8, 20)) # width, height

# get list of colors for plotting
list_colors = plt.get_cmap("tab10").colors

# loop over data and plot over corresponding frame
for p_i, data_idx in enumerate(range(data_start_idx, data_end_idx)):
# add subplot axes
ax = plt.subplot(math.ceil(data_end_idx / 5), 5, p_i + 1)
ax = plt.subplot(math.ceil(data_end_idx / 2), 2, p_i + 1)

# plot frame
# note: the video is indexed at every frame, so
Expand Down Expand Up @@ -230,12 +232,12 @@
# and the linearly interpolated values in green.

# initialise figure
fig = plt.figure(figsize=(15, 12))
fig = plt.figure(figsize=(8, 8))

# loop over frames
for frame_n in range(5):
for frame_n in range(6):
# add subplot axes
ax = plt.subplot(1, 6, frame_n + 1)
ax = plt.subplot(3, 2, frame_n + 1)

# plot frame
# note: the video is indexed at every frame, so
Expand Down Expand Up @@ -282,6 +284,8 @@
if frame_n == 0:
ax.legend()
ax.set_title(f"Frame {frame_n}")
ax.set_xlabel("x (pixels)")
ax.set_ylabel("y (pixels)")

fig.tight_layout()

Expand Down Expand Up @@ -321,3 +325,11 @@
writer.writerow(
[frame, individual, x, y, width, height, confidence]
)

# %%
# Remove the output file
# ----------------------
# We can remove the output file we have just created.
# "nbsphinx": "hidden"

os.remove(filepath)

0 comments on commit 4b7f339

Please sign in to comment.