Skip to content

Commit

Permalink
allows grouping of segments by label while plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
janaab11 committed Jul 5, 2021
1 parent f2f131d commit b9cc0be
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pyannote/core/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,36 @@ def plot_timeline(self, timeline: Timeline, ax=None, time=True):

# ax.set_aspect(3. / self.crop.duration)

def plot_annotation(self, annotation: Annotation, ax=None, time=True, legend=True):
def plot_annotation(self, annotation: Annotation, ax=None, time=True, legend=True, arrangement="pack"):
""" plots annotation
Parameters
----------
arrangement : str
To plot segments, they are grouped by certain rules, and each group is plotted
on a distinct line. `stack` will group segments according to their label.
`pack` will group segments optimally by timestamp, regardless of label.
Returns
-------
"""

if not self.crop:
self.crop = annotation.get_timeline(copy=False).extent()

cropped = annotation.crop(self.crop, mode='intersection')
labels = cropped.labels()
labels_dict = {label: i for i, label in enumerate(set(labels))}
segments = [s for s, _ in cropped.itertracks()]

ax = self.setup(ax=ax, time=time)

for (segment, track, label), y in zip(
cropped.itertracks(yield_label=True),
self.get_y(segments)):
if arrangement == "stack":
y = 1.0 - 1.0 / (len(labels) + 1) * (1 + labels_dict.get(label))
self.draw_segment(ax, segment, y, label=label)

if legend:
Expand Down

0 comments on commit b9cc0be

Please sign in to comment.