28 views (last 30 days)
Show older comments
Mad Gano on 27 Jun 2022
Commented: William Rose on 5 Jul 2022
Accepted Answer: William Rose
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.
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
William Rose on 27 Jun 2022
@Mad Gano,
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 Comments Show 7 older commentsHide 7 older comments
Show 7 older commentsHide 7 older comments
Mad Gano on 28 Jun 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#comment_2239750
- ColorMix.txt
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 on 28 Jun 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#comment_2240070
@Mad Gano, I will look at this tonight.
William Rose on 29 Jun 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#comment_2241030
Open in MATLAB Online
- ColorMix.txt
- ColorMix2.txt
@Mad Gano,
%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 on 29 Jun 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#comment_2242550
Thanks but I need the color interpretation between these speres
William Rose on 29 Jun 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#comment_2242915
@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 on 30 Jun 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#comment_2244350
I meant interpolation. it schuld look like FEM result. For each node I have X, Y, Z, CellSize and the StressValue
William Rose on 30 Jun 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#comment_2244755
@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 on 5 Jul 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#comment_2251290
thank you william I appreciate your support
William Rose on 5 Jul 2022
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#comment_2251315
@Mad Gano, you are welome. Good luck with your work.
Sign in to comment.
More Answers (1)
Pooja Kumari on 28 Jun 2022
Open in MATLAB Online
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:
https://in.mathworks.com/help/matlab/ref/surf.html
For more information on jet function, follow the below provided link:
https://in.mathworks.com/help/matlab/ref/jet.html#:~:text=c%20%3D%20jet%20returns%20the%20jet,intensities%20for%20a%20specific%20color.
Sincerely,
Pooja Kumari
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABGraphics2-D and 3-D PlotsSurfaces, Volumes, and PolygonsSurface and Mesh Plots
Find more on Surface and Mesh Plots in Help Center and File Exchange
Tags
- scatter
- scatteredinterpolant
- surf
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office