Previous topic

music21.freezeThaw

Next topic

music21.harmony

Table Of Contents

Table Of Contents

This Page

music21.graph

Object definitions for graphing and plotting Stream objects. The Graph object subclasses abstract fundamental graphing archetypes using the matplotlib library. The Plot object subclasses provide reusable approaches to graphing data and structures in Stream objects.

Functions

music21.graph.getColor(color)

Convert any specification of a color to a hexadecimal color used by matplotlib.

>>> graph.getColor('red')
'#ff0000'
>>> graph.getColor('Steel Blue')
'#4682b4'
>>> graph.getColor('#f50')
'#ff5500'
>>> graph.getColor([.5, .5, .5])
'#808080'
>>> graph.getColor(.8)
'#cccccc'
>>> graph.getColor([255, 255, 255])
'#ffffff'
music21.graph.plotStream(streamObj, *args, **keywords)

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

Note: plots requires 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')
../_images/PlotHistogramPitchSpace.png
>>> s = corpus.parse('bach/bwv57.8')
>>> s.plot('pianoroll')
../_images/PlotHorizontalBarPitchSpaceOffset.png
music21.graph.userFormatsToFormat(value)

Replace possible user format strings with defined format names as used herein. Returns string unaltered if no match.

music21.graph.userValuesToValues(valueList)

Given a value list, replace string with synonymes. Let unmatched values pass.

PlotHistogramPitchSpace

class music21.graph.PlotHistogramPitchSpace(streamObj, *args, **keywords)

A histogram of pitch space.

>>> s = corpus.parse('bach/bwv57.8')
>>> p = graph.PlotHistogramPitchSpace(s)
>>> p.id
'histogram-pitch'
>>> p.process() # with defaults and proper configuration, will open graph
../_images/PlotHistogramPitchSpace.png

PlotHistogramPitchSpace bases

PlotHistogramPitchSpace read-only properties

Read-only properties inherited from PlotStream:

PlotHistogramPitchSpace methods

Methods inherited from PlotStream:

PlotHistogramPitchClass

class music21.graph.PlotHistogramPitchClass(streamObj, *args, **keywords)

A histogram of pitch class

>>> s = corpus.parse('bach/bwv57.8')
>>> p = graph.PlotHistogramPitchClass(s)
>>> p.id
'histogram-pitchClass'
>>> p.process() # with defaults and proper configuration, will open graph
../_images/PlotHistogramPitchClass.png

PlotHistogramPitchClass bases

PlotHistogramPitchClass read-only properties

Read-only properties inherited from PlotStream:

PlotHistogramPitchClass methods

Methods inherited from PlotStream:

PlotHistogramQuarterLength

class music21.graph.PlotHistogramQuarterLength(streamObj, *args, **keywords)

A histogram of pitch class

>>> s = corpus.parse('bach/bwv57.8')
>>> p = graph.PlotHistogramQuarterLength(s)
>>> p.id
'histogram-quarterLength'
>>> p.process() # with defaults and proper configuration, will open graph
../_images/PlotHistogramQuarterLength.png

PlotHistogramQuarterLength bases

PlotHistogramQuarterLength read-only properties

Read-only properties inherited from PlotStream:

PlotHistogramQuarterLength methods

Methods inherited from PlotStream:

PlotWindowedKrumhanslSchmuckler

class music21.graph.PlotWindowedKrumhanslSchmuckler(streamObj, *args, **keywords)

Stream plotting of windowed version of Krumhansl-Schmuckler analysis routine. See KrumhanslSchmuckler for more details.

>>> s = corpus.parse('bach/bwv66.6')
>>> p = graph.PlotWindowedKrumhanslSchmuckler(s.parts[0])
>>> p.process() # with defaults and proper configuration, will open graph
../_images/PlotWindowedKrumhanslSchmuckler.png ../_images/legend-PlotWindowedKrumhanslSchmuckler.png

PlotWindowedKrumhanslSchmuckler bases

PlotWindowedKrumhanslSchmuckler read-only properties

Read-only properties inherited from PlotStream:

PlotWindowedKrumhanslSchmuckler methods

Methods inherited from PlotWindowedAnalysis:

Methods inherited from PlotStream:

PlotWindowedAmbitus

class music21.graph.PlotWindowedAmbitus(streamObj, *args, **keywords)

Stream plotting of basic pitch span.

>>> s = corpus.parse('bach/bwv66.6')
>>> p = graph.PlotWindowedAmbitus(s.parts[0])
>>> p.process() # with defaults and proper configuration, will open graph
../_images/PlotWindowedAmbitus.png ../_images/legend-PlotWindowedAmbitus.png

PlotWindowedAmbitus bases

PlotWindowedAmbitus read-only properties

Read-only properties inherited from PlotStream:

PlotWindowedAmbitus methods

Methods inherited from PlotWindowedAnalysis:

Methods inherited from PlotStream:

PlotScatterPitchSpaceQuarterLength

class music21.graph.PlotScatterPitchSpaceQuarterLength(streamObj, *args, **keywords)

A scatter plot of pitch space and quarter length

>>> s = corpus.parse('bach/bwv57.8')
>>> p = graph.PlotScatterPitchSpaceQuarterLength(s)
>>> p.id
'scatter-pitch-quarterLength'
>>> p.process()
../_images/PlotScatterPitchSpaceQuarterLength.png

PlotScatterPitchSpaceQuarterLength bases

PlotScatterPitchSpaceQuarterLength read-only properties

Read-only properties inherited from PlotStream:

PlotScatterPitchSpaceQuarterLength methods

Methods inherited from PlotStream:

PlotScatterPitchClassQuarterLength

class music21.graph.PlotScatterPitchClassQuarterLength(streamObj, *args, **keywords)

A scatter plot of pitch class and quarter length

>>> s = corpus.parse('bach/bwv57.8')
>>> p = graph.PlotScatterPitchClassQuarterLength(s)
>>> p.id
'scatter-pitchClass-quarterLength'
>>> p.process()
../_images/PlotScatterPitchClassQuarterLength.png

PlotScatterPitchClassQuarterLength bases

PlotScatterPitchClassQuarterLength read-only properties

Read-only properties inherited from PlotStream:

PlotScatterPitchClassQuarterLength methods

Methods inherited from PlotStream:

PlotScatterPitchClassOffset

class music21.graph.PlotScatterPitchClassOffset(streamObj, *args, **keywords)

A scatter plot of pitch class and offset

>>> s = corpus.parse('bach/bwv57.8')
>>> p = graph.PlotScatterPitchClassOffset(s)
>>> p.id
'scatter-pitchClass-offset'
>>> p.process()
../_images/PlotScatterPitchClassOffset.png

PlotScatterPitchClassOffset bases

PlotScatterPitchClassOffset read-only properties

Read-only properties inherited from PlotStream:

PlotScatterPitchClassOffset methods

Methods inherited from PlotStream:

PlotScatterPitchSpaceDynamicSymbol

class music21.graph.PlotScatterPitchSpaceDynamicSymbol(streamObj, *args, **keywords)

A graph of dynamics used by pitch space.

>>> s = corpus.parse('schumann/opus41no1', 2)
>>> p = graph.PlotScatterPitchSpaceDynamicSymbol(s)
>>> p.process()
../_images/PlotScatterPitchSpaceDynamicSymbol.png

PlotScatterPitchSpaceDynamicSymbol bases

PlotScatterPitchSpaceDynamicSymbol read-only properties

Read-only properties inherited from PlotStream:

PlotScatterPitchSpaceDynamicSymbol methods

Methods inherited from PlotStream:

PlotHorizontalBarPitchSpaceOffset

class music21.graph.PlotHorizontalBarPitchSpaceOffset(streamObj, *args, **keywords)

A graph of events, sorted by pitch space, over time

>>> s = corpus.parse('bach/bwv57.8')
>>> p = graph.PlotHorizontalBarPitchSpaceOffset(s)
>>> p.process() # with defaults and proper configuration, will open graph
../_images/PlotHorizontalBarPitchSpaceOffset.png

PlotHorizontalBarPitchSpaceOffset bases

PlotHorizontalBarPitchSpaceOffset read-only properties

Read-only properties inherited from PlotStream:

PlotHorizontalBarPitchSpaceOffset methods

Methods inherited from PlotStream:

PlotHorizontalBarPitchClassOffset

class music21.graph.PlotHorizontalBarPitchClassOffset(streamObj, *args, **keywords)

A graph of events, sorted by pitch class, over time

>>> s = corpus.parse('bach/bwv57.8')
>>> p = graph.PlotHorizontalBarPitchClassOffset(s)
>>> p.process() # with defaults and proper configuration, will open graph
../_images/PlotHorizontalBarPitchClassOffset.png

PlotHorizontalBarPitchClassOffset bases

PlotHorizontalBarPitchClassOffset read-only properties

Read-only properties inherited from PlotStream:

PlotHorizontalBarPitchClassOffset methods

Methods inherited from PlotStream:

PlotDolan

class music21.graph.PlotDolan(streamObj, *args, **keywords)

A graph of the activity of a parameter of a part (or a group of parts) over time. The default parameter graphed is Dynamics. Dynamics are assumed to extend activity to the next change in dynamics.

Numerous parameters can be configured based on functionality encoded in the PartReduction object.

If the fillByMeasure parameter is True, and if measures are available, each part will segment by Measure divisions, and look for the target activity only once per Measure. If more than one target is found in the Measure, values will be averaged. If fillByMeasure is False, the part will be segmented by each Note.

The segmentByTarget parameter is True, segments, which may be Notes or Measures, will be divided if necessary to show changes that occur over the duration of the segment by a target object.

If the normalizeByPart parameter is True, each part will be normalized within the range only of that part. If False, all parts will be normalized by the max of all parts. The default is True.

>>> s = corpus.parse('bwv66.6')
>>> dyn = ['p', 'mf', 'f', 'ff', 'mp', 'fff', 'ppp']
>>> i = 0
>>> for p in s.parts:
...     for m in p.getElementsByClass('Measure'):
...         m.insert(0, dynamics.Dynamic(dyn[i % len(dyn)]))
...         i += 1
...
>>> s.plot('dolan', fillByMeasure=True, segmentByTarget=True)
../_images/PlotDolan.png

PlotDolan bases

PlotDolan read-only properties

Read-only properties inherited from PlotStream:

PlotDolan methods

Methods inherited from PlotStream:

PlotScatterWeightedPitchSpaceQuarterLength

class music21.graph.PlotScatterWeightedPitchSpaceQuarterLength(streamObj, *args, **keywords)

A graph of event, sorted by pitch, over time

>>> s = corpus.parse('bach/bwv57.8')
>>> p = graph.PlotScatterWeightedPitchSpaceQuarterLength(s)
>>> p.process() # with defaults and proper configuration, will open graph
../_images/PlotScatterWeightedPitchSpaceQuarterLength.png

PlotScatterWeightedPitchSpaceQuarterLength bases

PlotScatterWeightedPitchSpaceQuarterLength read-only properties

Read-only properties inherited from PlotStream:

PlotScatterWeightedPitchSpaceQuarterLength methods

Methods inherited from PlotStream:

PlotScatterWeightedPitchClassQuarterLength

class music21.graph.PlotScatterWeightedPitchClassQuarterLength(streamObj, *args, **keywords)

A graph of event, sorted by pitch class, over time.

>>> s = corpus.parse('bach/bwv57.8')
>>> p = graph.PlotScatterWeightedPitchClassQuarterLength(s)
>>> p.process() # with defaults and proper configuration, will open graph
../_images/PlotScatterWeightedPitchClassQuarterLength.png

PlotScatterWeightedPitchClassQuarterLength bases

PlotScatterWeightedPitchClassQuarterLength read-only properties

Read-only properties inherited from PlotStream:

PlotScatterWeightedPitchClassQuarterLength methods

Methods inherited from PlotStream:

PlotScatterWeightedPitchSpaceDynamicSymbol

class music21.graph.PlotScatterWeightedPitchSpaceDynamicSymbol(streamObj, *args, **keywords)

A graph of dynamics used by pitch space.

>>> s = corpus.parse('schumann/opus41no1', 2)
>>> p = graph.PlotScatterWeightedPitchSpaceDynamicSymbol(s)
>>> p.process() # with defaults and proper configuration, will open graph
../_images/PlotScatterWeightedPitchSpaceDynamicSymbol.png

PlotScatterWeightedPitchSpaceDynamicSymbol bases

PlotScatterWeightedPitchSpaceDynamicSymbol read-only properties

Read-only properties inherited from PlotStream:

PlotScatterWeightedPitchSpaceDynamicSymbol methods

Methods inherited from PlotStream:

Plot3DBarsPitchSpaceQuarterLength

class music21.graph.Plot3DBarsPitchSpaceQuarterLength(streamObj, *args, **keywords)

A scatter plot of pitch and quarter length

>>> from music21.musicxml import testFiles
>>> s = converter.parse(testFiles.mozartTrioK581Excerpt)
>>> p = graph.Plot3DBarsPitchSpaceQuarterLength(s) 
>>> p.id
'3dBars-pitch-quarterLength'
>>> p.process() # with defaults and proper configuration, will open graph
../_images/Plot3DBarsPitchSpaceQuarterLength.png

Plot3DBarsPitchSpaceQuarterLength bases

Plot3DBarsPitchSpaceQuarterLength read-only properties

Read-only properties inherited from PlotStream:

Plot3DBarsPitchSpaceQuarterLength methods

Methods inherited from PlotStream:

Graph

class music21.graph.Graph(*args, **keywords)

A music21.graph.Graph is an object that represents a visual graph or plot, automating the creation and configuration of this graph in matplotlib. It is a low-level object that most music21 users do not need to call directly; yet, as most graphs will take keyword arguments that specify the look of graphs, they are important to know about.

The keyword arguments can be provided for configuration are: alpha (which describes how transparent elements of the graph are), colorBackgroundData, colorBackgroundFigure, colorGrid, title, doneAction (see below), figureSize, colors, tickFontSize, titleFontSize, labelFontSize, fontFamily, marker, markerSize.

Graph objects do not manipulate Streams or other music21 data; they only manipulate raw data formatted for each Graph subclass, hence it is unlikely that users will call this class directly.

The doneAction argument determines what happens after the graph has been processed. Currently there are three options, ‘write’ creates a file on disk (this is the default), while ‘show’ opens an interactive GUI browser. The third option, None, does the processing but does not write any output.

TODO: add color for individual points.

Graph methods

Graph.done(fp=None)

Implement the desired doneAction, after data processing

Graph.process()

process data and prepare plot

Graph.setAxisLabel(axisKey, label)
Graph.setAxisRange(axisKey, valueRange, paddingFraction=0.1)

Set the range for the axis for a given axis key (generally, ‘x’, or ‘y’)

ValueRange is a two-element tuple of the lowest number and the highest.

By default there is a padding of 10% of the range in either direction. Set paddingFraction = 0 to eliminate this shift

Graph.setData(data)
Graph.setDoneAction(action)

sets what should happen when the graph is created (see docs above) default is ‘write’.

Graph.setFigureSize(figSize)

Set the figure size as an x,y pair.

Scales all graph components but because of matplotlib limitations (esp. on 3d graphs) no all labels scale properly.

Graph.setIntegerTicksFromData(unsortedData, axisKey='y', dataSteps=8)

Set the ticks for an axis (usually ‘y’) given the data

Graph.setTicks(axisKey, pairs)

Set the tick-labels for a given graph or plot’s axisKey (generally ‘x’, and ‘y’) with a set of pairs

Pairs are tuples of positions and labels.

N.B. – both ‘x’ and ‘y’ ticks have to be set in order to get matplotlib to display either...

Graph.setTitle(title)
Graph.show()

Calls the show() method of the matplotlib plot. For most matplotlib back ends, this will open a GUI window with the desired graph.

Graph.write(fp=None)

Writes the graph to a file. If no file path is given, a temporary file is used.

Graph3DPolygonBars

class music21.graph.Graph3DPolygonBars(*args, **keywords)

Graph multiple parallel bar graphs in 3D.

This draws bars with polygons, a temporary alternative to using Graph3DBars, above.

Note: Due to matplotib issue Axis ticks do not seem to be adjustable without distorting the graph.

>>> import random
>>> g = graph.Graph3DPolygonBars()
>>> data = {1:[], 2:[], 3:[]}
>>> dk = list(data.keys())
>>> for i in range(len(dk)):
...    q = [(x, random.choice(range(10*(i+1)))) for x in range(20)]
...    data[dk[i]] = q
>>> g.setData(data)
>>> g.process()
../_images/Graph3DPolygonBars.png

Graph3DPolygonBars bases

Graph3DPolygonBars methods

Graph3DPolygonBars.process()

Methods inherited from Graph:

GraphColorGrid

class music21.graph.GraphColorGrid(*args, **keywords)

Grid of discrete colored “blocks” to visualize results of a windowed analysis routine.

Data is provided as a list of lists of colors, where colors are specified as a hex triplet, or the common HTML color codes, and based on analysis-specific mapping of colors to results.

>>> g = graph.GraphColorGrid()
>>> data = [['#55FF00', '#9b0000', '#009b00'], ['#FFD600', '#FF5600'], ['#201a2b', '#8f73bf', '#a080d5', '#403355', '#999999']]
>>> g.setData(data)
>>> g.process()
../_images/GraphColorGrid.png

GraphColorGrid bases

GraphColorGrid methods

GraphColorGrid.process()

Methods inherited from Graph:

GraphColorGridLegend

class music21.graph.GraphColorGridLegend(*args, **keywords)

Grid of discrete colored “blocks” where each block can be labeled

Data is provided as a list of lists of colors, where colors are specified as a hex triplet, or the common HTML color codes, and based on analysis-specific mapping of colors to results.

>>> g = graph.GraphColorGridLegend()
>>> data = []
>>> data.append(('Major', [('C#', '#00AA55'), ('D-', '#5600FF'), ('G#', '#2B00FF')]))
>>> data.append(('Minor', [('C#', '#004600'), ('D-', '#00009b'), ('G#', '#00009B')]))
>>> g.setData(data)
>>> g.process()
../_images/GraphColorGridLegend.png

GraphColorGridLegend bases

GraphColorGridLegend methods

GraphColorGridLegend.process()

Methods inherited from Graph:

GraphGroupedVerticalBar

class music21.graph.GraphGroupedVerticalBar(*args, **keywords)

Graph the count of on or more elements in vertical bars

Data set is simply a list of x and y pairs, where there is only one of each x value, and y value is a list of values

>>> from collections import OrderedDict
>>> g = graph.GraphGroupedVerticalBar()
>>> lengths = OrderedDict( [('a', 3), ('b', 2), ('c', 1)] )
>>> data = [('bar' + str(x), lengths) for x in range(3)]
>>> data
[('bar0', OrderedDict([('a', 3), ('b', 2), ('c', 1)])), ('bar1', OrderedDict([('a', 3), ('b', 2), ('c', 1)])), ('bar2', OrderedDict([('a', 3), ('b', 2), ('c', 1)]))]    
>>> g.setData(data)
>>> g.process()

GraphGroupedVerticalBar bases

GraphGroupedVerticalBar methods

GraphGroupedVerticalBar.labelBars(ax, rects)
GraphGroupedVerticalBar.process()

Methods inherited from Graph:

GraphHistogram

class music21.graph.GraphHistogram(*args, **keywords)

Graph the count of a single element.

Data set is simply a list of x and y pairs, where there is only one of each x value, and y value is the count or magnitude of that value

>>> import random
>>> g = graph.GraphHistogram()
>>> data = [(x, random.choice(range(30))) for x in range(50)]
>>> g.setData(data)
>>> g.process()
../_images/GraphHistogram.png

GraphHistogram bases

GraphHistogram methods

GraphHistogram.process()

Methods inherited from Graph:

GraphHorizontalBar

class music21.graph.GraphHorizontalBar(*args, **keywords)

GraphHorizontalBar bases

GraphHorizontalBar methods

GraphHorizontalBar.process()

Methods inherited from Graph:

GraphHorizontalBarWeighted

class music21.graph.GraphHorizontalBarWeighted(*args, **keywords)

GraphHorizontalBarWeighted bases

GraphHorizontalBarWeighted methods

GraphHorizontalBarWeighted.process()

Methods inherited from Graph:

GraphNetworxGraph

class music21.graph.GraphNetworxGraph(*args, **keywords)

Grid a networkx graph – which is a graph of nodes and edges. Requires the optional networkx module.

GraphNetworxGraph bases

GraphNetworxGraph methods

GraphNetworxGraph.process()

Methods inherited from Graph:

GraphNetworxGraph instance variables

GraphNetworxGraph.networkxGraph

An instance of a networkx graph object.

GraphScatter

class music21.graph.GraphScatter(*args, **keywords)

Graph two parameters in a scatter plot. Data representation is a list of points of values.

>>> g = graph.GraphScatter()
>>> data = [(x, x*x) for x in range(50)]
>>> g.setData(data)
>>> g.process()
../_images/GraphScatter.png

GraphScatter bases

GraphScatter methods

GraphScatter.process()

runs the data through the processor and if doneAction == ‘show’ (default), show the graph

Methods inherited from Graph:

GraphScatterWeighted

class music21.graph.GraphScatterWeighted(*args, **keywords)

A scatter plot where points are scaled in size to represent the number of values stored within.

>>> g = graph.GraphScatterWeighted()
>>> data = [(23, 15, 234), (10, 23, 12), (4, 23, 5), (15, 18, 120)]
>>> g.setData(data)
>>> g.process()
../_images/GraphScatterWeighted.png

GraphScatterWeighted bases

GraphScatterWeighted methods

GraphScatterWeighted.process()

Methods inherited from Graph:

Plot3DBars

class music21.graph.Plot3DBars(streamObj, *args, **keywords)

Base class for Stream plotting classes.

Plot3DBars bases

Plot3DBars read-only properties

Read-only properties inherited from PlotStream:

Plot3DBars methods

Methods inherited from PlotStream:

PlotFeatures

class music21.graph.PlotFeatures(streamList, featureExtractors, labelList=[], *args, **keywords)

FeatureExtractors can be ids or classes.

PlotFeatures bases

PlotFeatures methods

Methods inherited from PlotMultiStream:

PlotHistogram

class music21.graph.PlotHistogram(streamObj, *args, **keywords)

Base class for Stream plotting classes.

Plots take a Stream as their arguments, Graphs take any data.

PlotHistogram bases

PlotHistogram read-only properties

Read-only properties inherited from PlotStream:

PlotHistogram methods

Methods inherited from PlotStream:

PlotHorizontalBar

class music21.graph.PlotHorizontalBar(streamObj, *args, **keywords)

A graph of events, sorted by pitch, over time

PlotHorizontalBar bases

PlotHorizontalBar read-only properties

Read-only properties inherited from PlotStream:

PlotHorizontalBar methods

Methods inherited from PlotStream:

PlotHorizontalBarWeighted

class music21.graph.PlotHorizontalBarWeighted(streamObj, *args, **keywords)

A base class for plots of Scores with weighted (by height) horizontal bars. Many different weighted segments can provide a representation of a dynamic parameter of a Part.

PlotHorizontalBarWeighted bases

PlotHorizontalBarWeighted read-only properties

Read-only properties inherited from PlotStream:

PlotHorizontalBarWeighted methods

Methods inherited from PlotStream:

PlotMultiStream

class music21.graph.PlotMultiStream(streamList, labelList=None, *args, **keywords)

Approaches to plotting and graphing multiple Streams. A base class from which Stream plotting Classes inherit.

PlotMultiStream methods

PlotMultiStream.process()

This will process all data, as well as call the done() method. What happens when the done() is called is determined by the keyword argument doneAction; options are ‘show’ (display immediately), ‘write’ (write the file to a supplied file path), and None (do processing but do not write or show a graph).

Subclass dependent data extracted is stored in the self.data attribute.

PlotMultiStream.show()

Call internal Graphs show() method independently of doneAction set and run with process()

PlotMultiStream.write(fp=None)

Call internal Graphs write() method independently of doneAction set and run with process()

PlotScatter

class music21.graph.PlotScatter(streamObj, *args, **keywords)

Base class for 2D Scatter plots.

PlotScatter bases

PlotScatter read-only properties

Read-only properties inherited from PlotStream:

PlotScatter methods

Methods inherited from PlotStream:

PlotStream

class music21.graph.PlotStream(streamObj, flatten=True, *args, **keywords)

Approaches to plotting and graphing a Stream. A base class from which Stream plotting Classes inherit.

This class has a number of public attributes, but these are generally not intended for direct user application. The data attribute, for example, exposes the internal data format of this plotting routine for testing, but no effort is made to make this data useful outside of the context of the Plot.

PlotStream read-only properties

PlotStream.id

Each PlotStream has a unique id that consists of its format and a string that defines the parameters that are graphed.

PlotStream methods

PlotStream.process()

This will process all data, as well as call the done() method. What happens when the done() is called is determined by the keyword argument doneAction; options are ‘show’ (display immediately), ‘write’ (write the file to a supplied file path), and None (do processing but do not write or show a graph).

Subclass dependent data extracted is stored in the self.data attribute.

PlotStream.remapQuarterLength(x)

Remap a quarter length as its log2. Essentially it’s just math.log(x, 2), but 0 gives 0.

PlotStream.show()

Call internal Graphs show() method independently of doneAction set and run with process()

PlotStream.ticksDynamics(minNameIndex=None, maxNameIndex=None)

Utility method to get ticks in dynamic values:

>>> s = stream.Stream()
>>> a = graph.PlotStream(s)
>>> a.ticksDynamics()
[[0, '$pppppp$'], [1, '$ppppp$'], [2, '$pppp$'], [3, '$ppp$'], [4, '$pp$'], [5, '$p$'], [6, '$mp$'], [7, '$mf$'], [8, '$f$'], [9, '$fp$'], [10, '$sf$'], [11, '$ff$'], [12, '$fff$'], [13, '$ffff$'], [14, '$fffff$'], [15, '$ffffff$']]

A minimum and maximum dynamic index can be specified:

>>> a.ticksDynamics(3, 6)
[[3, '$ppp$'], [4, '$pp$'], [5, '$p$'], [6, '$mp$']]
PlotStream.ticksOffset(offsetMin=None, offsetMax=None, offsetStepSize=None, displayMeasureNumberZero=False, minMaxOnly=False, remap=False)

Get offset ticks. If Measure objects are found, they will be used to create ticks. If not, offsetStepSize will be used to create offset ticks between min and max.

If minMaxOnly is True, only the first and last values will be provided.

The remap parameter is not yet used.

>>> s = corpus.parse('bach/bwv281.xml')
>>> a = graph.PlotStream(s)
>>> a.ticksOffset() # on whole score, showing anacrusis spacing
[[0.0, '0'], [1.0, '1'], [5.0, '2'], [9.0, '3'], [13.0, '4'], [17.0, '5'], [21.0, '6'], [25.0, '7'], [29.0, '8']]
>>> a = graph.PlotStream(s.parts[0].flat) # on a Part
>>> a.ticksOffset() # on whole score, showing anacrusis spacing
[[0.0, '0'], [1.0, '1'], [5.0, '2'], [9.0, '3'], [13.0, '4'], [17.0, '5'], [21.0, '6'], [25.0, '7'], [29.0, '8']]
>>> a.ticksOffset(8, 12, 2)
[[9.0, '3']]
>>> a = graph.PlotStream(s.parts[0].flat) # on a Flat collection
>>> a.ticksOffset(8, 12, 2)
[[9.0, '3']]
>>> n = note.Note('a') # on a raw collection of notes with no measures
>>> s = stream.Stream()
>>> s.repeatAppend(n, 10)
>>> a = graph.PlotStream(s) # on a Part
>>> a.ticksOffset() # on whole score
[[0, '0'], [10, '10']]
PlotStream.ticksPitchClass(pcMin=0, pcMax=11)

Utility method to get ticks in pitch classes

Uses the default label for each pitch class regardless of what is in the Stream (unlike ticksPitchClassUsage())

>>> s = stream.Stream()
>>> a = graph.PlotStream(s)
>>> a.ticksPitchClass()
[[0, 'C'], [1, 'C$\\sharp$'], [2, 'D'], [3, 'E$\\flat$'], [4, 'E'], [5, 'F'], [6, 'F$\\sharp$'], [7, 'G'], [8, 'G$\\sharp$'], [9, 'A'], [10, 'B$\\flat$'], [11, 'B']]
PlotStream.ticksPitchClassUsage(pcMin=0, pcMax=11, showEnharmonic=True, blankLabelUnused=True, hideUnused=False)

Get ticks and labels for pitch classes.

If showEnharmonic is True (default) then when choosing whether to display as sharp or flat use the most commonly used enharmonic.

>>> s = corpus.parse('bach/bwv324.xml')
>>> s.analyze('key')
<music21.key.Key of G major>
>>> a = graph.PlotStream(s)
>>> for position, noteName in a.ticksPitchClassUsage(hideUnused=True):
...            print (str(position) + " " + noteName)
0 C
2 D
3 D$\sharp$
4 E
6 F$\sharp$
7 G
9 A
11 B
>>> s = corpus.parse('bach/bwv281.xml')
>>> a = graph.PlotStream(s)
>>> [x for x, y in a.ticksPitchClassUsage(showEnharmonic=True, hideUnused=True)]
[0, 2, 3, 4, 5, 7, 9, 10, 11]
>>> [x for x, y in a.ticksPitchClassUsage(showEnharmonic=True, blankLabelUnused=False)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
>>> s = stream.Stream()
>>> for i in range(60, 84):
...    n = note.Note()
...    n.ps = i
...    s.append(n)
>>> a = graph.PlotStream(s)
>>> [x for x, y in a.ticksPitchClassUsage(showEnharmonic=True)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
PlotStream.ticksPitchSpaceChromatic(pitchMin=36, pitchMax=100)

Utility method to get ticks in pitch space values.

>>> s = stream.Stream()
>>> a = graph.PlotStream(s)
>>> a.ticksPitchSpaceChromatic(20, 24)
[[20, 'G$\\sharp$0'], [21, 'A0'], [22, 'B$\\flat$0'], [23, 'B0'], [24, 'C1']]
>>> [x for x,y in a.ticksPitchSpaceChromatic(60, 72)]
[60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72]
PlotStream.ticksPitchSpaceOctave(pitchMin=36, pitchMax=100)

Utility method to get ticks in pitch space only for every octave.

>>> s = stream.Stream()
>>> a = graph.PlotStream(s)
>>> a.ticksPitchSpaceOctave()
[[36, 'C2'], [48, 'C3'], [60, 'C4'], [72, 'C5'], [84, 'C6'], [96, 'C7']]
PlotStream.ticksPitchSpaceQuartertone(pitchMin=36, pitchMax=100)

Utility method to get ticks in quarter-tone pitch space values.

PlotStream.ticksPitchSpaceQuartertoneUsage(pcMin=36, pcMax=72, showEnharmonic=False, blankLabelUnused=True, hideUnused=False)

Get ticks and labels for pitch space based on usage. That is, show the most commonly used enharmonic first.

PlotStream.ticksPitchSpaceUsage(pcMin=36, pcMax=72, showEnharmonic=False, blankLabelUnused=True, hideUnused=False)

Get ticks and labels for pitch space based on usage. That is, show the most commonly used enharmonic first.

>>> s = corpus.parse('bach/bwv324.xml')
>>> a = graph.PlotStream(s.parts[0])
>>> [x for x, y in a.ticksPitchSpaceUsage(hideUnused=True)]
[64, 66, 67, 69, 71, 72]
>>> s = corpus.parse('schumann/opus41no1/movement2.xml')
>>> a = graph.PlotStream(s)
>>> [x for x, y in a.ticksPitchSpaceUsage(showEnharmonic=True, hideUnused=True)]
[36, 38, 40, 41, 43, 44, 45, 47, 48, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72]
PlotStream.ticksQuarterLength(min=None, max=None, remap=True)

Get ticks for quarterLength.

If remap is True (the default), the remapQuarterLength() method will be used to scale displayed quarter lengths by log base 2.

Note that mix and max do nothing, but must be included in order to set the tick style.

>>> s = stream.Stream()
>>> for t in ['32nd', '16th', 'eighth', 'quarter', 'half']:
...     n = note.Note()
...     n.duration.type = t
...     s.append(n)
>>> a = graph.PlotStream(s)
>>> a.ticksQuarterLength()
[[-3.0, '0.1...'], [-2.0, '0.25'], [-1.0, '0.5'], [0.0, '1.0'], [1.0, '2.0']]
>>> a.ticksQuarterLength(remap = False)
[[0.125, '0.1...'], [0.25, '0.25'], [0.5, '0.5'], [1.0, '1.0'], [2.0, '2.0']]

The second entry is 0.125 but gets rounded differently in python 2 (1.3) and python 3 (1.2)

PlotStream.write(fp=None)

Call internal Graphs write() method independently of doneAction set and run with process()

PlotWindowedAardenEssen

class music21.graph.PlotWindowedAardenEssen(streamObj, *args, **keywords)

Stream plotting of windowed version of Aarden-Essen analysis routine. See AardenEssen for more details.

PlotWindowedAardenEssen bases

PlotWindowedAardenEssen read-only properties

Read-only properties inherited from PlotStream:

PlotWindowedAardenEssen methods

Methods inherited from PlotWindowedAnalysis:

Methods inherited from PlotStream:

PlotWindowedAnalysis

class music21.graph.PlotWindowedAnalysis(streamObj, processor=None, *args, **keywords)

Base Plot for windowed analysis routines.

PlotWindowedAnalysis bases

PlotWindowedAnalysis read-only properties

Read-only properties inherited from PlotStream:

PlotWindowedAnalysis methods

PlotWindowedAnalysis.process()

Process method here overridden to provide legend.

PlotWindowedAnalysis.write(fp=None)

Process method here overridden to provide legend.

Methods inherited from PlotStream:

PlotWindowedBellmanBudge

class music21.graph.PlotWindowedBellmanBudge(streamObj, *args, **keywords)

Stream plotting of windowed version of Bellman-Budge analysis routine. See BellmanBudge for more details.

PlotWindowedBellmanBudge bases

PlotWindowedBellmanBudge read-only properties

Read-only properties inherited from PlotStream:

PlotWindowedBellmanBudge methods

Methods inherited from PlotWindowedAnalysis:

Methods inherited from PlotStream:

PlotWindowedKrumhanslKessler

class music21.graph.PlotWindowedKrumhanslKessler(streamObj, *args, **keywords)

Stream plotting of windowed version of Krumhansl-Kessler analysis routine. See KrumhanslKessler for more details.

PlotWindowedKrumhanslKessler bases

PlotWindowedKrumhanslKessler read-only properties

Read-only properties inherited from PlotStream:

PlotWindowedKrumhanslKessler methods

Methods inherited from PlotWindowedAnalysis:

Methods inherited from PlotStream:

PlotWindowedSimpleWeights

class music21.graph.PlotWindowedSimpleWeights(streamObj, *args, **keywords)

Stream plotting of windowed version of Simple Weights analysis routine. See SimpleWeights for more details.

PlotWindowedSimpleWeights bases

PlotWindowedSimpleWeights read-only properties

Read-only properties inherited from PlotStream:

PlotWindowedSimpleWeights methods

Methods inherited from PlotWindowedAnalysis:

Methods inherited from PlotStream:

PlotWindowedTemperleyKostkaPayne

class music21.graph.PlotWindowedTemperleyKostkaPayne(streamObj, *args, **keywords)

Stream plotting of windowed version of Temperley-Kostka-Payne analysis routine. See TemperleyKostkaPayne for more details.

PlotWindowedTemperleyKostkaPayne bases

PlotWindowedTemperleyKostkaPayne read-only properties

Read-only properties inherited from PlotStream:

PlotWindowedTemperleyKostkaPayne methods

Methods inherited from PlotWindowedAnalysis:

Methods inherited from PlotStream: