데이터 시각화 기술과 같은 데이터로 트리의 시각적 효과를 만들려고합니다. 시각의 내 참조는 http://www.openprocessing.org/sketch/5918이지만, 임의의 부동 소수점 숫자가 만들어집니다. 동일한 비주얼을 생성 할 수 있습니까? 그러나이 경우 http://data.un.org/Data.aspx?q=mortality+&d=PopDiv&f=variableID%3a80처럼 복잡한 데이터로 생성 된 타원은 사용할 수 있습니까? Processing을 사용하고 있습니다.데이터 시각화를 사용하여 아트웍 만들기
라이브러리가 필요하며 임의의 변수 대신 데이터로 그릴 수 있도록 코드를 시작점으로 수정해야하는 방법은 무엇입니까?
color[] palette = {#262A40, #F2EAC2, #8C3F63};
Table mtl; // mtl = "Mortality"
int wide = 1000; // Width of window
int high = 600; // Height of window
float border = 75; // Size of border
float lb = border; // Left border
float rb = wide - border; // Right border
float bb = high - border; // Bottom border
float tb = border; // Top borders
float gw = rb - lb; // Grid width
float gh = bb - tb; // Grid height
float minX = 0;
float maxX = 10;
float minY = 0.00;
float maxY = 1.00;
float z = 1; // Zoom factor for scaling
float tx = wide/2; // Used for panning on x
float ty = high/2; // Used for panning on y
void setup() {
size(1000, 600);
smooth();
cursor(CROSS);
mtl = new Table("mortality3.tsv");
}
void draw() {
background(palette[0]);
scatter("mtl");
frame(border, palette[0]);
}
// scatter
void scatter(String tableObject) {
pushMatrix();
translate(tx, ty);
scale(z);
stroke(palette[1]);
strokeWeight(3);
int n = 936; // Got this manually from csv file
for (int i = 0; i < n; i++) {
float x = map(mtl.getFloat(i, 4), minX, maxX, -z*gw/2, z*gw/2);
float y = map(mtl.getFloat(i, 4), minY, maxY, z*gh/2, -z*gh/2);
point(x, y);
// Hover
float mx = map(mouseX, lb, rb, -(gw/2)/z - (tx - width/2)/z, (gw/2)/z - (tx - width/2)/z);
float my = map(mouseY, tb, bb, -(gh/2)/z - (ty - height/2)/z, (gh/2)/z - (ty - height/2)/z);
if (dist(mx, my, x, y) < 5) {
statString = "Country" +mtl.getString(i, 0) +
nf(mtl.getFloat(i, 2), 0, 2) + " Year " +
nf(mtl.getFloat(i, 1), 0, 3);
}
}
popMatrix();
}
은 또한 테이블 읽기 클래스 코드를 가지고,하지만 난이 오류가 "는, ArrayIndexOutOfBoundsException : 4"를 유지하고이 부분은 항상 강조 - return data[rowIndex][column]
class Table {
int rowCount;
String[][] data;
Table(String filename) {
String[] rows = loadStrings(filename);
data = new String[rows.length][];
for (int i = 0; i < rows.length; i++) {
if (trim(rows[i]).length() == 0) {
continue; // skip empty rows
}
if (rows[i].startsWith("#")) {
continue; // skip comment lines
}
// split the row on the tabs
String[] pieces = split(rows[i], TAB);
// copy to the table array
data[rowCount] = pieces;
rowCount++;
// this could be done in one fell swoop via:
//data[rowCount++] = split(rows[i], TAB);
}
// resize the 'data' array as necessary
data = (String[][]) subset(data, 0, rowCount);
}
int getRowCount() {
return rowCount;
}
// find a row by its name, returns -1 if no row found
int getRowIndex(String name) {
for (int i = 0; i < rowCount; i++) {
if (data[i][0].equals(name)) {
return i;
}
}
println("No row named '" + name + "' was found");
return -1;
}
String getRowName(int row) {
return getString(row, 0);
}
String getString(int rowIndex, int column) {
return data[rowIndex][column];
}
String getString(String rowName, int column) {
return getString(getRowIndex(rowName), column);
}
int getInt(String rowName, int column) {
return parseInt(getString(rowName, column));
}
int getInt(int rowIndex, int column) {
return parseInt(getString(rowIndex, column));
}
float getFloat(String rowName, int column) {
return parseFloat(getString(rowName, column));
}
float getFloat(int rowIndex, int column) {
return parseFloat(getString(rowIndex, column));
}
void setRowName(int row, String what) {
data[row][0] = what;
}
void setString(int rowIndex, int column, String what) {
data[rowIndex][column] = what;
}
void setString(String rowName, int column, String what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = what;
}
void setInt(int rowIndex, int column, int what) {
data[rowIndex][column] = str(what);
}
void setInt(String rowName, int column, int what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = str(what);
}
void setFloat(int rowIndex, int column, float what) {
data[rowIndex][column] = str(what);
}
void setFloat(String rowName, int column, float what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = str(what);
}
}
아무것도 지금 수에 대한 배출되지 않는 누군가 내가 왜 볼 수 있도록 도와 주는가? 내 TSV 파일에는 936 개의 행이 있습니다.
현재 양식에서이 질문은 스택 오버플로에 너무 광범위합니다. 스택 오버플로는 일반적으로 "어떻게해야합니까?"라는 질문에 대해 실제로 설계되지 않았습니다. 구체적으로 "X를 시도했는데 Y가 예상되었지만 대신 Z가 나타납니다"라는 질문에 대해 더 많이 고안되었습니다. 게시물을 편집하여 [mcve]를 포함 시키십시오. 이것은 귀하의 전체 프로젝트가 아닌 ** 귀하의 문제를보기 위해 실행할 수있는 예일뿐입니다. 가능할 때마다 하드 코딩 된 값을 사용하십시오. –
게시물을 편집했습니다. – Gladys