473,745 Members | 2,189 Online

# Plot Data Visualiation for 2D arrays

40 New Member
Does anyone know an easy way to visualise 2D arrays ? Any software that reads them in and displays them ?
Feb 6 '07 #1
9 8132
Ganon11
3,652 Recognized Expert Specialist
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?
Feb 6 '07 #2
dschulenburg
40 New Member
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....
Feb 7 '07 #3
Ganon11
3,652 Recognized Expert Specialist
The standard way to display 2D arrays is with a set of nested for...loops - an example is

Expand|Select|Wrap|Line Numbers
1. for (int r = 0; r < ROW_SIZE; r++) {
2.    for (int c = 0; c < COL_SIZE; c++) {
3.       cout << array[r][c] << " ";
4.    }
5.    cout << endl;
6. }
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?
Feb 7 '07 #4
dschulenburg
40 New Member
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 ?
Feb 7 '07 #5
macklin01
145 New Member
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:
Expand|Select|Wrap|Line Numbers
1. #include "EasyBMP.h"
2.
3. // ...
4.
5. // suppose you already have an array data[i][j]
6. // of size M x N
7.
8. // find the min and max of the array
9.
10. double min = 9e9;
11. double max = -9e9;
12. for( int i=0 ; i < M ;i++ )
13. {
14.  for( int j=0; j <N ; j++ )
15.  {
16.   if( data[i][j] < min )
17.   { min = data[i][j]; }
18.   if( data[i][j] > max )
19.   { max = data[i][j]; }
20.  }
21. }
22.
23. BMP Output;
24. Output.SetSize(M,N);
25.
26. // plot the pixels
27.
28. for( int i=0 ; i < M ; i++ )
29. {
30.  for( int j=0; j < N ; j++ )
31.  {
32.   double scaled_value = ( data[i][j] - min )/( max-min + 1e-16 );
33.   ebmpBYTE pixel_value = (ebmpBYTE) ( scaled_value * 255.0 );
34.   Output(i,j)->Red = pixel_value;
35.   Output(i,j)->Green = pixel_value;
36.   Output(i,j)->Blue = pixel_value;
37.  }
38. }
39.
40. // save the file
41.
42. Output.WriteToFile( "image.bmp" );
43.
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
Feb 7 '07 #6
macklin01
145 New Member
I didn't get the image uploaded in time. Here's a (highly degraded) version, to fit in the upload size limits. -- Paul
Feb 7 '07 #7
macklin01
145 New Member
Do'h!

Still wasn't fast enough. Darn those stringent limits! :) Here it is for real. ;) -- Paul
Attached Images
 frame00000145.JPG (29.8 KB, 859 views)
Feb 7 '07 #8
dschulenburg
40 New Member
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 ?
Feb 7 '07 #9
macklin01
145 New Member
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
Feb 7 '07 #10