How to plot 3D using a table (2024)

28 views (last 30 days)

Show older comments

Mad Gano on 27 Jun 2022

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table

Commented: William Rose on 5 Jul 2022

Accepted Answer: William Rose

I have for example this table

How to plot 3D using a table (2)

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

Sign in to comment.

Sign in to answer this question.

Accepted Answer

William Rose on 27 Jun 2022

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#answer_994840

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#answer_994840

@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

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

  • Link

    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

  • Link

    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

  • Link

    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

How to plot 3D using a table (7)

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

  • Link

    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

  • Link

    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

  • Link

    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

  • Link

    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.

How to plot 3D using a table (12)

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

  • Link

    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

  • Link

    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

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#answer_995065

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1749100-how-to-plot-3d-using-a-table#answer_995065

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

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.


How to plot 3D using a table (16)

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

How to plot 3D using a table (2024)

FAQs

How to plot 3D objects in matlab? ›

To plot a 3D surface from a data file in MATLAB, you will need to have the data file open in MATLAB. Once you have the data file available, you can use the plot3 command to plot the data. The plot3 command will create a 3D plot of the data. You can also use the surf command to create a 3D surface plot.

How to plot a surface in Matlab? ›

surface( X , Y , Z ) creates a primitive, three-dimensional surface plot. The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y . The color of the surface varies according to the heights specified by Z .

How do you describe a 3D plot? ›

A 3D surface plot is a three-dimensional graph that is useful for investigating desirable response values and operating conditions. A surface plot contains the following elements: Predictors on the x- and y-axes. A continuous surface that represents the response values on the z-axis.

Can you graph in 3D? ›

Three-dimensional graphs are a way to represent multi-variable functions with two inputs and one output. They're visualized by plotting input-output pairs in 3D space, resulting in a surface.

How do you plot a 3-D interactive plot in Python? ›

To plot 3-D plots in python, we need to import the mplot3d library from the standard installation of matplotlib library from python. As matplotlib is a third-party library, it doesn't come with a standard installation of python, so you need to install matplotlib before following this article.

What is the angle of a 3-D plot in MATLAB? ›

MATLAB automatically selects a viewpoint that is determined by whether the plot is 2-D or 3-D: For 2-D plots, the default is azimuth = 0° and elevation = 90°. For 3-D plots, the default is azimuth = -37.5° and elevation = 30°.

How to create a 3-D geometry in MATLAB? ›

Use multicuboid , multicylinder , or multisphere to create a 3-D geometry. Then assign the resulting geometry to the Geometry property of the model. For example, create a PDE model and add the following geometry formed by three spheres to the model. model = createpde; gm = multisphere([1,2,3]); model.

How to plot graph from table data in MATLAB? ›

Create a table containing three variables. Then pass the table as the first argument to the plot function followed by the names of the variables you want to plot. In this case, plot the Input variable on the x-axis and the Output1 variable on the y-axis. Notice that the axis labels match the variable names.

How do you make a good plot in MATLAB? ›

Direct link to this comment
  1. Increase the linewidth (2 or 3 is good).
  2. Add a grid.
  3. Add minor ticks to the axes.
  4. Plot as an area with solid line and semi-transparent fill.
  5. Set the axes limits appropriately.
  6. Add a legend.
  7. Change the font and fontsize to match the output size.
  8. Set the figure aspect ratio correctly.
Feb 27, 2016

How to plot with data in MATLAB? ›

Plotting Data Using MATLAB
  1. Introduction: Plotting Data Using MATLAB. ...
  2. Step 1: Opening the Program. ...
  3. Step 2: Creating a Script File. ...
  4. Step 5: Creating the Plot. ...
  5. Step 6: Adding Data Markers. ...
  6. Step 7: Adjusting the Marker Size. ...
  7. Step 8: Changing the Plot Color. ...
  8. Step 9: Formatting the Plot.

What is the formula for a 3D graph? ›

A graph in 3 dimensions is written in general: z = f(x, y). That is, the z-value is found by substituting in both an x-value and a y-value. The first example we see below is the graph of z = sin(x) + sin(y).

How to plot 3D in Excel? ›

Select the data that you want to use for your 3D plot. Go to the "Insert" tab in the Excel ribbon and select the desired chart type under the "Charts" section. Choose the 3D plot option that best fits your needs. Customize your chart by adding titles and labels and adjusting the appearance of the plot.

Top Articles
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 6170

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.