Skip to content

Rhythm of the lines

rhythm_plot(patterns, stressed, ax=None, labels=None)

A row per line and a cell per syllable of its pattern, numbered from 1: the stressed syllables in one color, the others in another, nothing past the end of a line, so that the columns of a meter and the lines that break it show at a glance.

Parameter Type Default Description
patterns list[str] - Patterns of the lines, a character per syllable
stressed str - Character of a stressed syllable in the patterns
ax Axes None Axes for the plot
labels dict[str, str] None Labels over the defaults: title, xlabel, ylabel, stressed, unstressed (the legend)

Patterns that are not a list of strings raise SourceTypeError, no lines SourceError; a stressed that is not one character, labels that merge_labels refuses and an ax that is not a matplotlib Axes raise ParameterError.

It is the function of the anyTS core with the Russian labels of ruts.constants.VISUALIZER_LABELS by default; labels sets labels over them. The patterns of the lines are the patterns of VerseStats, the character of a stressed syllable is PATTERN_STRESSED of ruts.verse_stats.

Two stanzas of Pushkin's «Winter Morning» - iambic tetrameter with the stress skipped on the sixth syllable:

from ruts import VerseStats
from ruts.datasets import PoetryCorpus
from ruts.verse_stats import PATTERN_STRESSED
from ruts.visualizers import rhythm_plot

records = PoetryCorpus().get_records(author="Александр Пушкин")
poem = next(record["text"] for record in records if record["title"] == "Зимнее утро")
vs = VerseStats("\n".join(poem.split("\n")[:12]))
rhythm_plot(vs.patterns, PATTERN_STRESSED)

ruts