Plot 2d image from 3D data Mathematica

In summary, the conversation discusses a problem with plotting a large dataset in a 2D image for laser-microscopy. The speaker shares their attempted solutions using the plotdata and ListPlot3D functions, but encounters an error. Another speaker suggests using the Import function and ArrayPlot to plot the data accurately, with the potential to customize the color function for a grey scale image.
  • #1
abikutn
10
0
hello guys,

I have a CSV file with hyuge set of data devided into 3 cols. Y position X position and corresponding intensity values.

I want to plot the image , my thesis is laser- microscopy. so a 2D plot ( density plot ) based on these values.

The following is what I have tried so far!
plotdata = Import["test2 10 10.csv", "Table"]
ListPlot3D[plotdata]
But above results in : is not a rectangular array larger than 2 x 2. >>

Can anyone help me how to deal with such a huge set of data and how to plot it as 2D image ( Grey scale is also fine )

Thank you,

abhi - abikutn@gmail.com
 

Attachments

  • test2 10 10.zip
    866 bytes · Views: 239
Physics news on Phys.org
  • #2
If your complete dataset is a square matrix of {x,y,z} in the same form as your small sample then this may work for you

xyz = Import["test2 10 10.csv"];
z = Partition[Map[Last, xyz], 10];
ArrayPlot[z, ColorFunctionScaling -> True]

That depends on your data being a square matrix and you need to set the size of the partition to restore your data to be a square matrix of z values.

This has been done of samples with a million data points and might work with larger values if needed.
 
  • #3
Thanks for your reply and support

"That depends on your data being a square matrix and you need to set the size of the partition to restore your data to be a square matrix of z values. "

by saying this: suppose I have 10 by 10 pixels with some intensity values Z for each pixel.

So partition meaning I have to split it 10 by 10 so that its a square matrix ?

and what is the meaning of machine size values ?

Thank you
 
  • #4
I suggest you take a look at the CSV file I have attached.

for example I have y{1->10} and x{1->10}
The way the values are recording in the CSV is as:

[step1: y=1, get values for X{1->10}
step2: increment y and repeat process till Y=max]

Will this affect in anyway how the plot forms based on its actual X and Y co ordinates ?
Just a question. I am not sure if you got my understanding.Basically won't the code you gave mix up all Z values with respect to their X and Y ?
 
  • #5
Remove that "Table" from import, use something like this:
Code:
plotdata = Import["test2 10 10.csv"]
z = GatherBy[plotdata, First][[All, All, 3]]
ArrayPlot[z, ColorFunction -> "Rainbow"]
 
  • #6
abikutn said:
I suggest you take a look at the CSV file I have attached.
;...
Just a question. I am not sure if you got my understanding.Basically won't the code you gave mix up all Z values with respect to their X and Y ?

I did use your CSV file to write and test the example I gave you.
Thank you for the example data. That makes it much easier to provide correct answers.
I believe that it does correctly keep the position of the Z values.

You should ALWAYS carefully test any code to make sure that it is correct.
Compare your matrix before any changes and after my calculation to verify this.

I had intended to use an even simpler method of obtaining the Z values but for some reason I just didn't think of a simpler method when I posted my first reply.
 
  • #7
Thank you! ... That was a good start ...

in the list density plot how can I change the color variation to grey scale image ? Is there a colorscaling function for grey scale just like how it can be done for RGB with ranibow ?

Abhi
 
  • #8
Just remove ColorFunction -> "Rainbow",
e.g.

Code:
ArrayPlot[z]
 

1. How can I plot a 2D image from 3D data in Mathematica?

To plot a 2D image from 3D data in Mathematica, you can use the ListPlot3D or Plot3D function. These functions take in a data set in the form of a list of coordinates and plot it in three dimensions. You can then use the ViewPoint and ViewVertical options to adjust the view and create a 2D image.

2. Can I plot multiple 2D images from the same 3D data set in Mathematica?

Yes, you can plot multiple 2D images from the same 3D data set in Mathematica by using the Show function. This function allows you to combine multiple plots into one, so you can plot different views or slices of the 3D data set in one image.

3. How do I add labels and axes to my 2D image plot in Mathematica?

To add labels and axes to your 2D image plot in Mathematica, you can use the PlotLabel, AxesLabel, and FrameLabel options. These allow you to customize the labels and axes of your plot with text and mathematical symbols.

4. Is it possible to change the color and style of my 2D image plot in Mathematica?

Yes, you can change the color and style of your 2D image plot in Mathematica by using the ColorFunction and PlotStyle options. These options allow you to choose a color scheme and specify the style of the plot, such as point size or line thickness.

5. Can I export my 2D image plot from Mathematica to other file formats?

Yes, you can export your 2D image plot from Mathematica to various file formats such as JPEG, PNG, PDF, and more. To do this, you can use the Export function and specify the desired file format as the second argument.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
13K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
Back
Top