Plot Data Visualiation for 2D arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dschulenburg
    New Member
    • Oct 2006
    • 40

    Plot Data Visualiation for 2D arrays

    Does anyone know an easy way to visualise 2D arrays ? Any software that reads them in and displays them ?
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Do you mean a way to display all the information in a 2D array in a good way, or a way for you personally to see what a 2D array is?

    Comment

    • dschulenburg
      New Member
      • Oct 2006
      • 40

      #3
      Originally posted by Ganon11
      Do you mean a way to display all the information in a 2D array in a good way, or a way for you personally to see what a 2D array is?
      I am looking for a way to display the data. I have a code that spits out 2D arrays and would like to shiw them as plots as they correspond to a data set with two dimensions. I basically need a Y and a X axis and then the value for every coordiante point....

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        The standard way to display 2D arrays is with a set of nested for...loops - an example is

        Code:
        for (int r = 0; r < ROW_SIZE; r++) {
           for (int c = 0; c < COL_SIZE; c++) {
              cout << array[r][c] << " ";
           }
           cout << endl;
        }
        This will print out each value in one column of the array, separated by one space each. It will then move to a new line and start with the next column. The resulting output would be something like an inverted x, y coordinate, with each r value being a y coordinate and each c value being an x coordinate. You could switch this by outputting array[c][r].

        Is this what you meant?

        Comment

        • dschulenburg
          New Member
          • Oct 2006
          • 40

          #5
          I can see how you can print out the values in an array that way. What I need is more a software that allows to display them easily. Imagin your array is an image (e.g. a photo) that has values for different colors or intesitys that you want to have a look at. There must be something that reads an array in and displays it as an image...? Does that make sense ?

          Comment

          • macklin01
            New Member
            • Aug 2005
            • 145

            #6
            I wrote some open source code to visualize 2D arrays. Have a look at the EasyBMP project, and take a look at the DataPlotter program.

            IIRC, I need to update that program, so let me know if you encounter problems. But a pre-compiled version is included.

            Also, here's a very simple way to visualize a 2D array in grayscale:
            Code:
            #include "EasyBMP.h"
            
            // ...
            
            // suppose you already have an array data[i][j] 
            // of size M x N
            
            // find the min and max of the array
            
            double min = 9e9;
            double max = -9e9;
            for( int i=0 ; i < M ;i++ )
            {
             for( int j=0; j <N ; j++ )
             {
              if( data[i][j] < min )
              { min = data[i][j]; }
              if( data[i][j] > max )
              { max = data[i][j]; }
             }
            }
            
            BMP Output;
            Output.SetSize(M,N);
            
            // plot the pixels
            
            for( int i=0 ; i < M ; i++ )
            {
             for( int j=0; j < N ; j++ )
             {
              double scaled_value = ( data[i][j] - min )/( max-min + 1e-16 );
              ebmpBYTE pixel_value = (ebmpBYTE) ( scaled_value * 255.0 );
              Output(i,j)->Red = pixel_value; 
              Output(i,j)->Green = pixel_value;
              Output(i,j)->Blue = pixel_value;
             }
            }
            
            // save the file
            
            Output.WriteToFile( "image.bmp" );
            I can show you fancier color functions, other than grayscale later. (I use a homebrew "rainbow" function myself.) In fact, I just rewrote some visualization software for my cancer simulator this afternoon using this type of deal. Here's a typical screenshot. :-) We can also do other fancy things, like resizing, labeling, etc., later. First, just get the data on the screen. ;-)

            I hope this helps! -- Paul

            Comment

            • macklin01
              New Member
              • Aug 2005
              • 145

              #7
              I didn't get the image uploaded in time. Here's a (highly degraded) version, to fit in the upload size limits. -- Paul

              Comment

              • macklin01
                New Member
                • Aug 2005
                • 145

                #8
                Do'h!

                Still wasn't fast enough. Darn those stringent limits! :) Here it is for real. ;) -- Paul
                Attached Files

                Comment

                • dschulenburg
                  New Member
                  • Oct 2006
                  • 40

                  #9
                  Originally posted by macklin01
                  Do'h!

                  Still wasn't fast enough. Darn those stringent limits! :) Here it is for real. ;) -- Paul
                  Paul, thanks, I'll have a quick look at your webpage ! Does that only work for C++ or also in C ?

                  Comment

                  • macklin01
                    New Member
                    • Aug 2005
                    • 145

                    #10
                    Originally posted by dschulenburg
                    Paul, thanks, I'll have a quick look at your webpage ! Does that only work for C++ or also in C ?
                    No problem, dr. s.

                    While most of the code uses C, EasyBMP is implemented as a few C++ classes, particularly the BMP class. (The object-oriented nature of C++ makes it much easier to implement the read/write functions, etc.) Thanks -- Paul

                    Comment

                    Working...