After many years of just messing around, I’ve started formal guitar lessons this year. A lot of my instruction includes learning the notes on the fret board, the different keys of music, scales, some basic music theory, and so forth. I’ve taken a lot of hand written notes during my instructional sessions and recently started transcribing a lot of those digitally. It occurred to me that Jupyter Notebook and Python might be a fantastic way to depict some of the concepts I’m learning. So, here is Part 1 of some of my guitar notes with the help of Jupyter Notebook and Python.
The 12 Keys
I won’t take the time to explain the notes and basic pattern in music as that information can be found all over the internet. The first idea I wanted to construct was a grid of the 12 keys and the notes within each key. My instructor and I have also talked a lot about the relative minor in each major key, so I wanted my graphic to convey that point, too. I put together this code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
# make up my list of notes
chromatic_scale_ascending = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
# since I usually start on the low E string, rearrange the notes starting on E
scale_from_e = (chromatic_scale_ascending + chromatic_scale_ascending)[4:16]
# the scale pattern:
# root, whole step, whole step, half step, whole step, whole step, whole step, half step
key_steps = [2, 2, 1, 2, 2, 2] # on the guitar, a whole step is two frets
major_keys = []
for root in scale_from_e:
three_octaves = scale_from_e * 3
steps_from_root = three_octaves.index(root)
major_scale = [root]
# construct the unique notes in the scale
for step in key_steps:
steps_from_root += step
major_scale.append(three_octaves[steps_from_root])
# span the scale across 3 octaves
major_keys.append(major_scale * 2 + [root])
df_major_keys = pd.DataFrame(major_keys)
df_major_keys.columns = df_major_keys.columns + 1 # start counting notes at 1 instead of 0
# use this function to highlight the relative minor scales in orange
def highlight_natural_minor(data):
df = data.copy()
df.iloc[:,:] = 'font-size:20px;height:30px'
df.iloc[:,5:13] = 'background-color: lightgray; font-size:20px'
return df
print('The 12 keys and the notes within them:')
df_major_keys.style.apply(highlight_natural_minor, axis=None)
Which produced this handy graphic:
For simplicity, I used sharps in my keys instead of flats. The highlighted part of the table marks the relative minor portion of the major key.
The notes of the fret board
Probably one of the best ways to learn the notes on your guitar’s fret board is to trace out the fret board on a blank piece of paper and start filling in each note by hand. Do that a few hundred times and you’ll probably start remembering the notes. Being lazy, though, I wanted to have my computer do that work for me. Here’s the code I came up with to write out the fret board:
standard_tuned_strings = ['E', 'A', 'D', 'G', 'B', 'E']
chromatic_scale_ascending = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
col_names = ['Low E', 'A', 'D', 'G', 'B', 'High E']
fretboard_notes = []
for string in standard_tuned_strings:
start_pos = chromatic_scale_ascending.index(string)
fretboard_notes.append((chromatic_scale_ascending + chromatic_scale_ascending)[start_pos+1:start_pos+13])
df_fretboard = pd.DataFrame(np.array(fretboard_notes).T, index=np.arange(1, 13), columns=col_names)
df_fretboard.index.name = 'fret'
def highlight_select_frets(data):
fret_markers = [2, 4, 6, 8, 11]
df = data.copy()
df.iloc[:,:] = 'font-size:20px'
df.iloc[fret_markers,:] = 'background-color: lightgray; font-size:20px'
return df
df_fretboard.style.apply(highlight_select_frets, axis=None)
More notes to come, so stay tuned! (Puns intended)
Recent Comments