User’s Guide, Chapter 22: Graphing

There are a number of ways to visualize notes, scores, and measures in music21.

Visualizing Streams in Plots

While the show() method provides common musical views of a Stream, a visual plot a Stream’s elements is very useful. Sometimes called a piano roll, we might graph the pitch of a Note over its position in a Measure (or offset if no Measures are defined). The plot() method permits us to create a plot of any Stream or Stream subclass (note that the additional package matplotlib needs to be installed to run graphs, see Extending Music21 with Additional Software for more information). There are a large variety of plots: see music21.graph for a complete list. There are a number of ways to get the desired plot; one, as demonstrated below, is to provide the name of the plot as a string. We can also add a keyword argument for the title of the plot (and configure many other features).

from music21 import *
sBach = corpus.parse('bach/bwv57.8')
sBach.getElementById('Soprano').plot('PlotHorizontalBarPitchSpaceOffset', title='Soprano')
../_images/usersGuide_22_graphing_5_0.png

Just getting started here... hang tight. :-)