Object definitions for graphing and plotting Stream objects.

The Graph object subclasses primitive, abstract fundamental graphing archetypes using the matplotlib library. The PlotStream object subclasses provide reusable approaches to graphing data and structures in Stream objects.

The most common way of using plotting functions is to call .plot() on a Stream.


music21.graph.plotStream(streamObj, graphFormat=None, xValue=None, yValue=None, zValue=None, **keywords)

Given a stream and any keyword configuration arguments, create and display a plot.

Note: plots require matplotib to be installed.

Plot methods can be specified as additional arguments or by keyword. Two keyword arguments can be given: format and values. If positional arguments are given, the first is taken as format and the rest are collected as values. If format is the class name, that class is collected. Additionally, every PlotStream subclass defines one format string and a list of values strings. The format parameter defines the type of Graph (e.g. scatter, histogram, colorGrid). The values list defines what values are graphed (e.g. quarterLength, pitch, pitchClass).

If a user provides a format and one or more values strings, a plot with the corresponding profile, if found, will be generated. If not, the first Plot to match any of the defined specifiers will be created.

In the case of PlotWindowedAnalysis subclasses, the DiscreteAnalysis subclass indentifiers list is added to the Plot’s values list.

Available plots include the following:

>>> s = corpus.parse('bach/bwv57.8')
>>> s.plot('histogram', 'pitch')
>>> s = corpus.parse('bach/bwv57.8')
>>> s.plot('pianoroll')