Today, we're going to represent a guitar chord on a circular diagram. Let's start with a basic circle that gets annotated with the different note names relative to the fundamental tone.
%matplotlib inline
import pylab as pl
import matplotlib as mpl
from pylab import cos, sin
def plot_circle():
circle = mpl.patches.Circle((0, 0), radius=1, fill=False)
a = pl.gca()
a.add_patch(circle)
pl.xlim(-1.1, 1.1)
pl.ylim(-1.1, 1.1)
a.set_aspect('equal')
a.set_axis_off()
def annotate_and_label():
note_labels = ['1', 'b2', '2', 'b3', '3', '4', 'b5', '5', 'b6', '6', 'b7', '7']
for i in range(12):
theta = pl.pi/2 - 2 * pl.pi / 12. * i
x, y = cos(theta), sin(theta)
#pl.plot((0, x), (0, y))
pl.plot((x), (y), 'ok', )
pl.annotate(note_labels[i], (x, y), (1.15 * x, 1.15 * y))
def plot_note(note, with_line=False):
note = note % 12
theta = pl.pi/2 - 2 * pl.pi / 12. * note
x, y = cos(theta), sin(theta)
# plot line before point
if with_line:
pl.plot((0, x), (0, y), '-k')
# plot point
pl.plot((x), (y), 'o', markeredgecolor='blue', markeredgewidth=10)
plot_circle()
annotate_and_label()
plot_note(2)
plot_note(7, with_line=True)
Ok, now that we know how to plot these things, let's go live with a plot that shows us a major chord.
# setup diagram
plot_circle()
annotate_and_label()
# plot chord
major7_chord = [0, 4, 7, 11]
for note in major7_chord:
plot_note(note, with_line=True)
Hey, how about we just shift the notes and plot all the different inversions of the major 7 chord ?
pl.figure(figsize=(10, 10))
for i in range(4):
pl.subplot(2, 2, i + 1)
plot_circle()
annotate_and_label()
chord = map(lambda note: (note - major7_chord[i]) % 12, major7_chord)
for note in chord:
plot_note(note, with_line=True)
pl.title('Inversion %s' % (i + 1))
#pl.tight_layout(pad=0.8)