How to plot 3D using a table

I have for example this table
I would like to plot this table 3D so that the values in between have to be interpreted with respect to the balloon size but also with smooth color change (here I use e.g. colormap(jet)).
P.s
Actually I can't understand the surf(X,Y,Z,C) because X,Y,Z are only vectors and C can't be defined.

 Respuesta aceptada

William Rose
William Rose el 27 de Jun. de 2022

0 votos

Please sypply your data as a mat file or text file instead of an image. Thank you.
I do not understand your goal. Do you want to plot spheres of different radii and colors, with centers at the specified x,y,z values? If so, it appears that there will b a number of pairs of balloons that mostly overlap eachother.
Do the specified x,y,z points represent samples of a surface, and you want to interpolate to get other points on the surface? If so, then you might be able to interpolate z values at other x,y locations, or you can interpolate radii or colors at other x,y locations, or you can do all three, but those interpolations must be done independently. Is that your goal? If it is your goal, then it will be difficult, because the distribution of points in the table is very uneven in the x-y plane. X values range from 1.41 to 3.66, but are unevenly spread. Y values are also unevenly spread: y=4.69 (n=2), y=6.56 (n=7), y=8.36 (n=1), y=8.44 (n=25).

9 comentarios

Mad Gano
Mad Gano el 28 de Jun. de 2022
Thanks for your reply. Actually the table is lot bigger than that (1M x 5) matrix
"Do you want to plot spheres of different radii and colors, with centers at the specified x,y,z values"
yes actually that what i want, i don't care if it overlap, but if there any space on between, it schuld get automaticlly a interpolated color. At the end ill have some colord 3D modell but Ballons anymore
William Rose
William Rose el 28 de Jun. de 2022
@Mad Gano, I will look at this tonight.
%plotColoredSpheres.m
%W. Rose 2022
clear
A=importdata('ColorMix2.txt'); %read data from file
xc=A.data(:,1); yc=A.data(:,2); zc=A.data(:,3); %center coordinates
vol=A.data(:,4); %volumes
BallColor=A.data(:,5); %colors
r=(vol*3/(4*pi)).^(1/3); %radii
figure;
for i=1:length(xc)
%Next: Create arrays for sphere with 6x6 faces
[xs,ys,zs]=sphere(6);
%Next: Adjust sphere radius and position to desired values
xs=xs*r(i)+xc(i); ys=ys*r(i)+yc(i); zs=zs*r(i)+zc(i);
cs=BallColor(i)*ones(size(zs)); %color for sphere
surf(xs,ys,zs,cs); %plot one sphere
hold on
end
axis equal
xlabel('X'); ylabel('Y'); zlabel('Z'); %axis labels
colorbar %add color bar to plot
The last line of file ColorMix.txt has a sphere that is far away from all the other spheres. Inclusion of that sphere in the plot makes the others look tiny and squished into one corner. Therefore I deleted the last line of ColorMix.txt and saved the edited file as ColorMix2.txt. If you want to see the result with the outlier sphere, edit the file name in line 1 to 'ColorMix.txt'.
When you run the code in Matlab, you will be able to click and drag in the plot, to rotate the plot in 3D.
Good luck!
Mad Gano
Mad Gano el 29 de Jun. de 2022
Thanks but I need the color interpretation between these speres
William Rose
William Rose el 29 de Jun. de 2022
@Mad Gano, Please explain precisely what you mean by a "color interpretation between these spheres". The existing color bar interprets the colors for the viewer. Do you mean interpolation, not interpretation?
In an earlier comment, you wrote
"i don't care if it overlap, but if there any space on between, it schuld get automaticlly a interpolated color. At the end ill have some colord 3D modell but Ballons anymore"
I cannot parse that statement. Please explain more clearly what you seek. If you can express it mathmatically, that would be great. If you can provide an image of the kind of plot you hope to get, that would be great. If you explain the meaning of the data (what physical quantities are represented by x, y, z, volume, and "color") and what you hope to learn from a visual representation of the data, that would be even better.
Mad Gano
Mad Gano el 30 de Jun. de 2022
I meant interpolation. it schuld look like FEM result. For each node I have X, Y, Z, CellSize and the StressValue
William Rose
William Rose el 30 de Jun. de 2022
@Mad Gano, Here is an example of an FEM result, in which a value such as stress is known at each point in a mesh, and the plot shows that stress as color, interpolated across the mesh. It is from this discussion.
Is this what you want? The plot above is for a 2D mesh, but your nodes are in 3D. There is no easy way to plot stress with color in 3D, because that makes a 4D plot (x,y,z,stress). You can do it by a) plotting stress on a plane that slices through the 3D volume, or b) by plotting stress on a surface that exists in 3D.
If you want a), then you need to interpolate in 3D. Matlab's interp3() does that, but the input data needs to be defined at all points on a 3D grid of points, and yours is not. You will also need to define the plane of the slice. This can be done by specifying 3 locations in the plane, or by specifying one point in the plane and a normal vector.
If you want b), you need to define the mesh with a mesh data structure. Basically this is a list of coordinates and a list of triangular faces, where each face is defined by a set of 3 corner numbers . See here for an example. See here to learn how to generate 2D and 3D meshes in Matlab.
If you can provide an image that is like what you want, that would probably help.
Mad Gano
Mad Gano el 5 de Jul. de 2022
thank you william I appreciate your support
William Rose
William Rose el 5 de Jul. de 2022
@Mad Gano, you are welome. Good luck with your work.

Iniciar sesión para comentar.

Más respuestas (1)

Pooja Kumari
Pooja Kumari el 28 de Jun. de 2022
Dear Mad Gano,
It is my understanding that you want to plot the given table in 3D using surf function and the values X,Y,Z have to be interpreted with respect to balloon size.
surf(X,Y,Z,C) creates a 3-D surface plot with x-y plane defined by X and Y and C taken surface color only.
You can only plot 3D graph using surf with three parameters at a time. So, if you want to plot your data with respect to balloon size.
%with different combination of X,Y,Z with respect to %BalloonSize.
surf(X,Y,BalloonSize)
surf(Y,Z,BalloonSize)
surf(Z,X, BalloonSize)
For more information on surf function, you can follow the provided documentation below:
For more information on jet function, follow the below provided link:
Sincerely,
Pooja Kumari

Preguntada:

el 27 de Jun. de 2022

Comentada:

el 5 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by