"""
Sequence index plots with pattern occurrences
=============================================

The index plot of social-science sequence analysis (Brzinsky-Fay, 2014) draws
every sequence as a row of colored cells. Combined with the mined patterns it
answers *where* a frequent sequence occurs: the earliest occurrence of each
highlighted pattern is marked, and sorting by the patterns brings the
supporting sequences to the top.
"""

import matplotlib.pyplot as plt

import spmviz as sv
from spmviz.viz import plot_sequence_index

db = sv.datasets.make_alarm_cascades(400, random_state=0)
plot_sequence_index(db, max_sequences=80, sort="pattern",
                    highlight=["P-LOWFLOW P-TRIP OP-PUMPSTART", "C-HITEMP C-VALVE"], max_length=14)
# %%
# Sorted by length
# ----------------
plot_sequence_index(db, max_sequences=80, sort="length", max_length=14)
plt.show()
