Plotting 3D Surface Graph: Issues & Solutions

In summary, the conversation discusses the difficulty in plotting a 3d surface graph with limited data points. The use of griddata and surf commands are suggested, but it is discovered that the problem lies in the lack of data points. Other methods, such as using the meshgrid and subplot commands, are suggested to better display the data. A sample code is provided for plotting a surface graph with a function.
  • #1
morry
136
0
Im trying to plot a 3d surface graph, but I am having trouble.

I have 3 data inputs, x,y,z. I also had X and Y=Y' which are the min:int:max values. Because I only have a few points, I tried to do Z= griddata(x,y,z,X,Y) to interpolate the results. But it comes up with an error saying that not all points could converge.

When I type surf(X,Y,Z) a new window opens and I get a blank graph.

Any ideas why this may be happening?
Cheers
 
Physics news on Phys.org
  • #2
3d grids are a little tricky the first time you try to create them.

The easiest way I've found to get them up and running is to use the meshgrid command to create your x and y coordinates, and then create your z values from those grids.

If this doesn't answer your question, let me know and I'll track down some sample code for you.
 
  • #3
I actually just read the command description for the griddata command you used, and I think I misinterprited your problem.

Can you cut and paste the relevant code you used here, and say what form the input variables have? Either that or just attach .mat and .m files? (you will probably need to zip them to allow the forum software to accept them)
 
  • #4
Thanks enigma, here is the file. I don't have winzip, so I just saved it in a txt file.

Im pretty certain that the problem is to do with griddata, but I have no idea why.

Thanks again.
 

Attachments

  • thermo.txt
    2.7 KB · Views: 490
  • #5
ok. the reason it's giving you the errors is because you don't have enough points for it to fill in a surface.

If you just plot(x,y), you'll see that your data falls into a roughly linear set running from ~(1500,130) to ~(4000,35). What you're asking it to do when you use the surf command is to plot a rectangular grid surface covering the entire 1500-4100 in the x direction and 30-130 in the y direction. Since MATLAB has no information about anything other than along that line, it can't possibly come up with a surface for you.

What you can do is do a plot3(x,y,z) command, but that doesn't look much easier to see. Do you _need_ to display both x and y as independant variables? If so, you might be able to do a bunch of lines from (xi,yi,0) to (xi,yi,zi) and then put a star or something on the z=0 axis and label the z value.

What does the data represent? I'm sure there is an easier way to display your results.
 
Last edited:
  • #6
I'm thinking that if you do need to show both x and y, your best bet would be to use the subplot command to split the window into 2. Put X-Y on the top half, and X-Z on the bottom half.

Also, because you have so few points, I'd be sure to use stars instead of lines to display the data. You don't have enough points to justify using the lines.
 
Last edited:
  • #7
Well I need to graph engine speed, torque and efficiency. Whats frustrating is that I have instructions here from the lecturer and following those leads me up the garden path. :)

The graph should look something like this:
http://www.mame.mu.oz.au/thermofluids/mesh3.gif [Broken]

Ill try that plot3 command, I don't really know what that last post of yours meant.

Thanks!
 
Last edited by a moderator:
  • #8
It's not going to look like that gif because you simply don't have enough points. Plot X vs. Y and you'll see what I mean.

Check out the subplot command. It let's you split up a plot window into multiple graphs. I think the format is subplot(2,1,1) and subplot (2,1,2) to split it into 2 vertically stacked plots and access the first (top) and second (bottom) plot respectively.
 
  • #9
Hmm, might have to ask my lecturer about this one. The graph is going to look pretty dodgy if I only have a handful of points to work with.
Thanks.
 
  • #10
lets say i wanted to do a surface plot of z = x*y^2*e^sin(3*x*y);

well first define the range of your x vector let's say -5 to 5

so x = linspace(-5,5) (this by default will put 100 pts between the values)

lets let y go from -6 to 6 so one again

y = linspace(-6,6,101) (now were using 101 elements)

this next part is SUPER CRUCIAL as it makes the grid for the x and y axes

[x y] = meshgrid(x,y)

this will make a dim(Y) by dim(X) grid for each of your variables

so now X is no longer a vector it is a 101x100 matrix

same thing with Y

You can look at these matrices more in detail in the MATLAB workspace if you really want. or just simply by typing mesh(x) or mesh(y)

now to plot your function you must remember to include periods for element-wise multiplication so...

z = x.*y.^2.*exp(sin(3*x.*y))

(notice you don't need a period between the 3 and x in the e term because 3 is a scalar)

now we simply just type mesh(x,y,z) and we will get the surface plot

if you want things to look smoother then just increase the number of point in the linspace commands. If you use too many it will take a while to plot

if you want the figure to move around continuously when rotating it, try not to use too many points. Also after you have computed z, all the commands

mesh(x,y,z) surf(x,y,z) contour(x,y,z) willl all work

try running them and compare the differences. Good Luck!
 

1. What software can I use to plot 3D surface graphs?

There are various software options available for plotting 3D surface graphs, such as MATLAB, Python's Matplotlib library, and Grapher for Mac. It ultimately depends on your personal preference and the specific features and capabilities you require.

2. How can I handle missing data when plotting a 3D surface graph?

One solution is to use interpolation techniques to estimate missing data points. This can be done using built-in functions in software like MATLAB or by writing custom code. Another option is to remove the missing data points entirely and plot the remaining data.

3. How can I improve the visualization of my 3D surface graph?

Some tips for improving the visualization of a 3D surface graph include adjusting the color scheme, adding grid lines, and adjusting the lighting and perspective. It can also be helpful to experiment with different software and tools to find the best visualization for your data.

4. What are some common issues that may arise when plotting 3D surface graphs?

Some common issues include distorted or unreadable axes, incorrect scaling, and missing or incorrect data. These issues can often be resolved by adjusting the settings and parameters of the graph or using different visualization techniques.

5. How can I determine the accuracy of my 3D surface graph?

One way to determine the accuracy of a 3D surface graph is to compare it to other visualizations of the same data, such as 2D graphs or scatter plots. Additionally, you can calculate the error or deviation between the graph and the actual data values. It is also important to consider the limitations of the data and the software used to create the graph.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
75
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
203
Back
Top