We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online. Pages: 1 Line graph (Read 3268 times)
 AAK Line graph Jun 14th, 2010, 7:38am   I'm trying to make a line graph using data imported from a txt file. I want each line to go from one point to the next, but all I'm getting is a bunch of lines coming out of the last point on the right going to every other point. Here's the code that does that: Code:```if (abs(mouseX-(NII*650+800)) < lim &&  abs(mouseY-(-OIII*350+350)) < lim) { String spectra = "S5_hi_spectra_" + nf(i,5) + ".txt"; println(spectra); String[] spec = loadStrings (spectra); for (int j = 1; j < 866; j++) { String[] spec1 = splitTokens(spec[j], WHITESPACE);    float[] spec2 = parseFloat(spec1); for (int k = 2; k < 866; k++) { String[] spec3 = splitTokens(spec[k], WHITESPACE);     spec4 = parseFloat(spec3); }    pushMatrix();    pushStyle();    fill(0);    stroke(0);    translate(50,900);    scale(0.35);    line(spec2*100-1000, -spec2*10000, spec4*100-1000, -spec4*10000); ```It worked fine when I used ellipses for points, instead of trying to make a line, but I need the points to be connected. Cedric Re: Line graph Reply #1 - Jun 14th, 2010, 7:59am   if the ellipse code worked.use beginShape(LINES);vertex(x and y of your ellispe);endShape();instead  twitter.com/CedricKiefer
 AAK Re: Line graph Reply #2 - Jun 14th, 2010, 8:06am   I tried what you suggested, and now it doesn't plot anything at all. Updated code: Code:```if (abs(mouseX-(NII*650+800)) < lim && //transform  abs(mouseY-(-OIII*350+350)) < lim) { String spectra = "S5_hi_spectra_" + nf(i,5) + ".txt"; println(spectra); String[] spec = loadStrings (spectra); for (int j = 1; j < 866; j++) { String[] spec1 = splitTokens(spec[j], WHITESPACE);    float[] spec2 = parseFloat(spec1);    pushMatrix();    pushStyle();    fill(0);    stroke(0);    translate(50,900);    scale(0.35);    beginShape(LINES);    vertex(spec2*100-1000, -spec2*10000);    endShape(); ``` Cedric Re: Line graph Reply #3 - Jun 14th, 2010, 8:29am   you need to place begin and endShape around all of your points, not just one. its a bit hard to draw a line if you only got one point. maybe i should have explained it better  twitter.com/CedricKiefer
 AAK Re: Line graph Reply #4 - Jun 14th, 2010, 8:35am   The points are (spec2*100-1000, -spec2*10000), there's a whole list of almost 900 numbers in each one of those. Cedric Re: Line graph Reply #5 - Jun 14th, 2010, 8:53am   not sure if i get the way you draw your points."*100-1000" doesnt seem like a good way to map your points. anyway. Do you draw all of the points every frame ?to draw a line, you need at least two points. the beginShape(LINE) function is still really useful if you have a whole list of points you want to connect by lines.But in your case, i only see one single point. not even a loop to draw more of them ... so how do you draw the rest of your points ? nf(i,5) there is an i, is that part of a loop i cant see ?  twitter.com/CedricKiefer
 AAK Re: Line graph Reply #6 - Jun 14th, 2010, 9:04am   All the points are drawn every frame. This graph is actually within a bigger graph - when you roll over a point on the bigger graph, you get this smaller one. That's where the i in the nf(i,5) comes from. I just use the "*100-1000" to make the points fit where I want them to.  I could probably find a better way to put that in the code, but this worked fine with the ellipses, so I don't think that's the problem. Here's the entire code for the graph that actually works, with the part we're working on highlighted: Code:```int numPics = 292; // change with number of points, numPics = # picturesPImage[] pics = new PImage[numPics];PFont font;PFont small;PFont large;String[] num;float[] values;void setup() {  size(1000,950);  smooth();  font = loadFont("Serif-15.vlw");  small = loadFont("Serif-12.vlw");  large = loadFont("LiSongPro-32.vlw");  for ( int k = 0; k < numPics; k++) {    String imageName =  "S5_stamp_" + nf(k, 5) + ".png";    pics[k] = loadImage(imageName);      }}void draw() {  background(255);  String[] data = loadStrings ("S5_quantities_4.txt"); for (int i = 0; i < numPics; i++) {                num = splitTokens(data[i], WHITESPACE);    values = parseFloat(num);    ellipseMode(CENTER);  stroke(150);  fill(255);  float NII = log(values/values)/log(10);  float OIII = log(values/values)/log(10);if(values == 1) {      fill(0,0,255);      stroke(0,0,255);    ellipse(NII*650+800,-OIII*350+350,3,3); //transform, disk  }else if(values == 2) {    fill(0,255,0);    stroke(0,255,0);  ellipse(NII*650+800,-OIII*350+350,3,3); //transform, peculiar  }  else {    fill(255,0,0);    stroke(255,0,0);  ellipse(NII*650+800,-OIII*350+350,3,3); //transform, spheroid}  int lim = 2;  if(abs(mouseX-(NII*650+800)) < lim && //transform  abs(mouseY-(-OIII*350+350)) < lim) {    image(pics[i-1], 50, 500, 120, 120);    textFont(font);    fill(0);    text("NII/Ha" + " " + NII + "  " + "OIII/Hb" + " " + OIII, 50, 630, 300, 60);  }     if (abs(mouseX-(NII*650+800)) < lim && //transform  abs(mouseY-(-OIII*350+350)) < lim) { String spectra = "S5_hi_spectra_" + nf(i,5) + ".txt"; println(spectra); String[] spec = loadStrings (spectra); for (int j = 0; j < 866; j++) { String[] spec1 = splitTokens(spec[j], WHITESPACE);    float[] spec2 = parseFloat(spec1);    pushMatrix();    pushStyle();    fill(0);    stroke(0);    translate(50,900);    scale(0.35);    ellipse(spec2*100-1000, -spec2*10000,1,1);    line(-11,0,951,0);    line(0,-550,0,10);    for (int k = 0; k < width; k+=100) {      line(k,0,k,20);    }   for (int k = 0; k < 600; k+=100) {      line(0,-k,-20,-k);    }    popStyle();    popMatrix(); }    textFont(small);     float[] yscale = {0.05, 0.04, 0.03, 0.02, 0.01, 0.0};    for (int k = 0; k < 6; k++) {      text(nf(yscale[k],1,2), 15, k*35+725);    }    float[] xscale = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};    for (int k = 0; k < 10; k++) {      text(nf(xscale[k],0,0), k*35+45, 920);    }    text("Flux v. Wavelength", 175, 700); } } // axes and scalesstroke(0);line(0,2,width,2); //horizontalline(width-2,-height,width-2,height);    //verticaltextFont(font);fill(0);text("Log[NII]6584/Ha", 10, 35);text("Log[OIII]5007/Hb", width-150, height-10);fill(0,0,255);text("disk", 10, 645);fill(0,255,0);text("peculiar", 10, 660);fill(255,0,0);text("spheroid", 10, 675);fill(0);for(int i = 0; i < height; i+=86) {  line(width-4,i,width,i);}float[] yscale = {  1.25, 1, 0.75, 0.5, 0.25, 0, -0.25, -0.5, -0.75, -1.0, -1.25, -1.5, -1.75};for (int i = 0; i < 12; i++) {  text(nf(yscale[i],0,2), width-40, (i-1)*86);}for(int i = -13; i < width; i+=167) {  line(i,0,i,4);}float[] xscale = {  -1.25, -1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1.0};for(int i = 1; i < 6; i++) {  text(nf(xscale[i],0,2), (i)*167-13, 15);}} ```This draws an entire graph of ellipses, spec2*100-1000 vs -spec2*10000.  Pages: 1