Question on label of a plot
in
Programming Questions
•
7 months ago
Hi,
I'm a very newbye of Processing, but yet I'm loving it ..
I need to take the x-axes label on a plot. Data come from a file that you can find
here.
I write this code, but it doesn't work. .. It doesn't write any labels .. anyone can help me? thank's
- int yearInterval=10;
- int i=0;
- int j=0;
- int count=0;
- ArrayList<Float> Time;
- ArrayList<Float> Pressure;
- ArrayList<Float> Flow;
- ArrayList<Float> Eadi;
- String lines[];
- float dataMin, dataMax;
- float plotX1, plotY1;
- float plotX2, plotY2;
- void setup() {
- size(720, 405);
- lines=loadStrings("001_ServoCurveData_0000.nta");
- //println (lines);
- Time = new ArrayList<Float>();
- Pressure = new ArrayList<Float>();
- Flow = new ArrayList<Float>();
- Eadi = new ArrayList<Float>();
- plotX1 = 50;
- plotX2 = width - plotX1;
- plotY1 = 60;
- plotY2 = height - plotY1;
- smooth( );
- noLoop();
- }
- void draw() {
- background(224);
- // Show the plot area as a white box.
- fill(255);
- rectMode(CORNERS);
- noStroke( );
- rect(plotX1, plotY1, plotX2, plotY2);
- stroke(#5679C1);
- for ( i=28; i < lines.length/10;i++ ) { // lines.length
- for (j=0;j<7;j++) {
- String [] field= splitTokens(lines[i]);
- Time.add(float(field[0])*0.01);
- Pressure.add(float(field[4])*0.01);
- Flow.add(float(field[5])*0.0001);
- Eadi.add(float(field[6])*0.01);
- }
- }
- //println(Time.size());
- //println(Pressure.size());
- // println(Time.get(Time.size()-2));
- // println(Time.get(Time.size()-1));
- for ( int yi=1;yi<Pressure.size();yi++) {
- float _x = map(Time.get(yi-1), Time.get(0), Time.get(Time.size()-1), plotX1, plotX2);
- float _y = map(Pressure.get(yi-1), 0, 30, plotY1, plotY2);
- float x = map(Time.get(yi), Time.get(0), Time.get(Time.size()-1), plotX1, plotX2);
- float y = map(Pressure.get(yi), 0, 30, plotY1, plotY2);
- line(_x, _y, x, y);
- //point(x, y);
- }
- drawYearLabels();
- }
- void drawYearLabels() {
- fill(0);
- textSize(10);
- textAlign(CENTER, TOP);
- for (int row = 0; row < Time.size(); row++) {
- //println(Time.get(row)-0.25 % yearInterval);
- if (Time.get(row)-0.25 % yearInterval == 0) {
- float x = map(Time.get(row), Time.get(0), Time.get(Time.size()-1), plotX1, plotX2);
- //println(int(Time.get(row)));
- text(Time.get(row), x, plotY2 + 10);
- }
- }
- }
1