Thursday, September 23, 2010

Visualizing Data

I sent Dr. Goddard an e-mail explaining how I wanted to create a 3d surface plot using an incomplete data set. He mentioned several solutions, but his first choice was to use Mathematica instead of trying to create a graph using just java. One of my goals was to have the Desktop application be competently free and open source, and relying on Mathematica violates this. However, the solution is so simple and elegant that I'm not going to reinvent the wheel just to keep things open source.

I wrote a quick script to generate a set of sample data

import java.util.Random;
public class datamake {

    public static void main(String[] args) {
        Random gen = new Random();
        String output = "";
       
        output += ("ListSurfacePlot3D[{");       
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                if(gen.nextInt() %4 == 0)
                output += ("{" + i + "," + j + "," + gen.nextInt(5) + "},");
            }
        }
        output = output.substring(0,output.length()-1);
        output += ("}]");
        System.out.println(output);
    }

}

and Mathematica generated this surface plot.

If you look closely a the code, you will notice that it only generates approximately 25% of the data required.  The algorithm automatically interpolates the missing data.  Pretty sweet huh? 

No comments:

Post a Comment