Visualizing Data: My Late Night Rendezvous with Earthquakes

Nick Kunz
Data Mining the City
3 min readOct 12, 2017

My first thought, I probably need a faster computer. This exercise led me deep into burning the midnight oil. My second thought, I probably should limit the amount of data I use for the practical purposes of visualization. It reminded me of an old adage I recall hearing in the military, “there’s two ways we do things here; the right way, and again!” Much like the military, Python demands the right way, or you’ll be doing it again.

Exhibited here is earthquake data from a 24-hour time horizon on Oct 10th, 2017 taken from the United States Geological Survey. When thinking about how I should visualize it, I did reference the precedents published before this. However, I wanted to exhibit the magnitude information in a slightly different way that might be more appropriate for this particular data set. Also, because the data was temporal (but not a time-series), I thought it would be useful to explicitly denote the time of record. In addition, I thought other important attributes associated with each event would be worth including, such as the location. If I were to write a sequel, wedding a slippy map to this visual would be in the treatment.

Overall, this was a great way to experiment with data visualization in Python. Above you can find the output and below you can find the code.

RLTW

import csvdef setup():

size(1200, 550)
with open("allquakes20171010.csv") as f:
reader = csv.reader(f)
header = reader.next()
global magnitudes
magnitudes = []
global locations
locations = []

global times
times = []
for field in reader:
magnitude = float(field[4])
magnitudes.append(magnitude)
location = str(field[13])
locations.append(location)

time = splitTokens(field[0], "T .")
times.append(time)
def draw():

# visualization variables
background(0)
barScalar = 100
barWidth = 2.99
barTime = 4

textPositionX = 3.33
textPositionY = 400

# interactivity variables
mouseTrackerX = 1.5
zeroCoordinateMagnitude = 0
zeroCoordinateLocation = 0
zeroCoordinateTime = 0

# lights, camera, action
for magnitude in magnitudes:
if mouseX < zeroCoordinateMagnitude - barWidth / mouseTrackerX or mouseX > zeroCoordinateMagnitude + barWidth / mouseTrackerX:
fill(90)
else:
fill(60, 179, 113)
textSize(12)
textAlign(LEFT)
text(magnitude, width / textPositionX, textPositionY + 45)
ellipse(zeroCoordinateMagnitude, height / 2, barWidth, magnitude * barScalar)
zeroCoordinateMagnitude = zeroCoordinateMagnitude + barTime
for location in locations:
if mouseX < zeroCoordinateLocation - barWidth / mouseTrackerX or mouseX > zeroCoordinateLocation + barWidth / mouseTrackerX:
fill(0)
else:
fill(60, 179, 113)
textSize(12)
textAlign(LEFT)
text(location, width / textPositionX + 4, textPositionY + 65)
zeroCoordinateLocation = zeroCoordinateLocation + barTime
for time in times:
if mouseX < zeroCoordinateTime - barWidth / mouseTrackerX or mouseX > zeroCoordinateTime + barWidth / mouseTrackerX:
fill(0)
else:
fill(60, 179, 113)
textSize(12)
textAlign(LEFT)
text(time[1], width / textPositionX + 4, textPositionY + 85)
zeroCoordinateTime = zeroCoordinateTime + barTime

# static text
fill(60, 179, 113)
textSize(18)
text("24 Hour Earthquake Activity: October 10th, 2017", 20, textPositionY - 360)
fill(150)
textSize(12)
textAlign(RIGHT)
text("Magnitude:", width / textPositionX, textPositionY + 45)

fill(150)
textSize(12)
textAlign(RIGHT)
text("Location:", width / textPositionX, textPositionY + 65)

fill(150)
textSize(12)
textAlign(RIGHT)
text("Time:", width / textPositionX, textPositionY + 85)

fill(150)
textSize(12)
textAlign(RIGHT)
text("Source:", width / textPositionX, textPositionY + 105)
fill(60, 179, 113)
textSize(12)
textAlign(LEFT)
text("USGS 2017", 365, textPositionY + 105)

--

--