Plotting a 3D scalar field as a coloured 3D scatter graph

61 views (last 30 days)
Hello,
I have a 3D temperature data set: a 3D array giving the temperature at each point in a 3D cartesian space, with coordinates x, y, z. I would like to find a way of visualising this data set. I thought it would be straightforward to plot a 3D scatter graph, and at each point on the graph the temperature is represented by a colour. However, I'm not sure how to use the scatter3 function.
Can anyone please help me to plot this data?
Specifically my data is:
x=linspace(-0.3,0.3,16); y=linspace(-0.3,0.3,16); z=linspace(-0.3,0.3,16);
Then I have a 3D array, Temperature(x,y,z) which has a different value for each set x,y,z.
Thanks.

Accepted Answer

Patrick Kalita
Patrick Kalita on 2 May 2012
Edited: John Kelly on 27 May 2014
If you want to use scatter3, you can pass it your x, y, and z vectors which will define where markers will be drawn. Then your temperature data can be used to control the size and/or color of the markers. According to your description, x, y, and z are vectors whereas Temperature is a 3D array. That seems slightly odd, but I suppose plausible. At any rate, you'd need to at least convert that 3D array into a vector before passing it to scatter3:
scatter3( x, y, z, [], Temperature(:) ); % Use Temperature to set marker color
That makes some assumptions about how the data is actually stored, but it's a best guess based on the information you've given.
If you have a lot of data points, then scatter3 isn't the best option.
  2 Comments
Paul
Paul on 3 May 2012
Thank you very much Patrick - you're right that all I had to do was convert the temperature from an array. The temperature (which I have called A) is a 3D array because it is a function of the position: A(x,y,z), so each position in space has a value depending on its coordinates.
I used the following loop to make A into a scalar for each coordinate (x,y,z) and plot A as the colour of each point:
Nx=10;
x1=0.3;
x=linspace(-x1,x1,Nx);y=linspace(-x1,x1,Nx);z=linspace(-x1,x1,Nx);
for a=1:Nx
for b=1:Nx
for c=1:Nx
d=x(a);e=y(b);f=z(c);
g=A(a,b,c);
scatter3(d,e,f,50,g);
end
end
end
Where A is a 3D array which is a function of x,y,z: A(x,y,z).
I also had a look at the links you added, and was able to make some slices to further visualise the data, and as a result I have a very nice 3D scatter and slice plot which shows the data very clearly!
Thanks a lot.
wendy wang
wendy wang on 4 Feb 2015
Edited: wendy wang on 4 Feb 2015
Hi Paul, I took the suggestion to visualize my data with scatter3. I have (x, y, z, P) data set, where x, y ,z are coordiantes with size of 1*N. P is the parameter at the corresponding location and it also has the size of 1*N. I can successfully visualize my data using scatter3, but can not do the slice plot. How do you do the slice plot for such case with scatter data? It looks like the slice function only apply to 3-D array of x, y,z and P. Can I do it in a 1-D array?
By the way, I have a lot of data points, besides the scatter3, is there any other better idea to visualize the data in 3D space with color indicating the P parameter? Thanks for any advice!!
Wendy

Sign in to comment.

More Answers (1)

uri iger
uri iger on 7 Aug 2018
Hi! so if I have about 14M points, what do I use?
Thanks a lot! Uri

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!