W3_VisualizingEarthquakes

Yuan Hua
Data Mining the City
2 min readOct 5, 2017
import csv
def setup():
size(1050, 120)

with open("quakes.csv") as f:
reader = csv.reader(f)
header = reader.next() # Skip the header row.

global magnitudes
magnitudes = []
locations = []

# loop to get magnitude data from csv file
for row in reader:
magnitude = float(row[4])
magnitudes.append(magnitude)
def draw():
background(0)
scalar=-10
x = 0

for magnitude in magnitudes:
if mouseX < x or mouseX > x+5:
fill(255,255,255)
rect(x, height / 1.5, 5, magnitude*scalar)
else:
fill(255,0,0)
rect(x, height / 1.5, 5, magnitude*scalar)
# text
if magnitude == max(magnitudes):
if mouseX < width/2:
text ('The highest magnitude is ' + str(magnitude), mouseX, mouseY)
else:
text ('The highest magnitude is ' + str(magnitude), mouseX-180, mouseY)
rect(x-5, height / 1.5, 15, magnitude*scalar)
elif magnitude == min(magnitudes):
if mouseX < width/2:
text ('The lowest magnitude is ' + str(magnitude), mouseX, mouseY)
else:
text ('The lowest magnitude is ' + str(magnitude), mouseX-180, mouseY)
rect(x-2, height / 1.5, 9, magnitude*scalar)
else:
if mouseX < width/2:
text ('The magnitude is ' + str(magnitude), mouseX, mouseY)
else:
text ('The magnitude is ' + str(magnitude), mouseX-130, mouseY)
rect(x, height / 1.5, 5, magnitude*scalar)
x += 6

Magnitudes of earthquakes were visualized through bar charts. When you move the mouse to the bar, you can see the actual value of the magnitude. The highest and lowest value are highlighted.

--

--