// This example is based on the Datasaurus dataset by
// Alberto Cairo
float[] data1, data2;
void setup() {
size(600, 600);
// Read data
String[] lines = loadStrings("ScaryData.csv");
//printArray(lines);
println(lines.length);
// Parse it
data1 = new float[lines.length];
data2 = new float[lines.length];
for (int i = 0; i < lines.length; i++) {
String[] pieces = split(lines[i], ",");
data1[i] = float(pieces[0]);
data2[i] = float(pieces[1]);
}
//printArray(data1);
println("Read...parsed.");
println(max(data1));
println(min(data1));
// Compute mean...
//noLoop();
} // setup()
void draw() {
background(255);
// Draw axes
// X and & Axes
strokeWeight(1);
stroke(0);
line(50, height-50, width-50, height-50);
line(50, height-50, 50, 50);
// Labels
for (int index = 0; index <= 100; index += 10) {
fill(0);
strokeWeight(1);
stroke(0);
text(str(index), map(index, 0, 100, 50, width-50), height-40);
textAlign(RIGHT);
text(str(index), 50, map(index, 0, 100, height-50, 50));
}
// Draw Scatter plot
for (int i = 0; i < data1.length; i++) {
// plot data1[i], data2[i]
float x = map(data1[i], 0, 100, 50, width-50);
float y = map(data2[i], 0, 100, height-50, 50);
strokeWeight(10);
stroke(0);
point(x, y);
// Interactivity
if (dist(mouseX, mouseY, x, y) <= 10) {
stroke(255, 0, 0);
fill(255, 0, 0);
strokeWeight(1);
//println(mouseX, mouseY);
text(data1[i]+", "+data2[i], mouseX, mouseY);
}
}
} // draw()