Processingで散布図を作成するグラフ関数
xy_plot.pdeとxy_graph.pde data_3.csvのzip
xy_graph
FloatTable.pdeは、Ben Flyのサイトからダウンロード
xy_graph.pde
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
//xy_graph.pde FloatTable data; float ydataMin, ydataMax, xdataMin, xdataMax; float plotX1, plotY1, plotX2, plotY2; float labelX, labelY; int row = 0, rowCount = 0; int row_event1 = 1163; // recip liver take-out int row_event2 = 1609; // donor liver put-in String xlabel = "SVV"; String ylabel = "CI"; int xvolumeInterval = 10, yvolumeInterval = 1; int xvolumeIntervalMinor = 1, yvolumeIntervalMinor = 1; PFont plotFont; void setup() { size(405, 405); data = new FloatTable("data_3.tsv"); xdataMin = 0; xdataMax = 50; ydataMin = 0; ydataMax = 12; plotX1 = 50; plotX2 = width - plotX1; plotY1 = 50; plotY2 = height - plotY1; labelX = 15; labelY = height - 10; plotFont = createFont("SansSerif", 20); textFont(plotFont); frameRate(600); smooth(); } void draw() { background(224); fill(255); rectMode(CORNERS); noStroke(); rect(plotX1, plotY1, plotX2, plotY2); draw_all_labels_lines(); strokeWeight(3); for (int row = 0; row < rowCount; row++) { if(row < row_event1) { stroke(#6fc833); } else { if (row < row_event2) { stroke(#ffd700); } else {stroke(#bd1f30);} } drawDataPoints(0, row); } rowCount = rowCount + 1; saveFrame("frames/######.png"); } void drawDataPoints(int col, int row) { if (data.isValid(row, col)) { float xvalue = data.getFloat(row, col); float yvalue = data.getFloat(row, col+1); float x = map(xvalue, xdataMin, xdataMax, plotX1, plotX2); float y = map(yvalue, ydataMin, ydataMax, plotY2, plotY1); point(x, y); } } |