简体   繁体   中英

3d plot with given 2d data

I want to understand how the 2d data is related to z axis to get the 3d plots

let us say that i have x=[-1:0.1:1] , vector

and y=[1 2 3 4 5 4 3 2 1 0]

a plot of y Vs x will have peak of 5 and slope down to both sides at x=0.5 how to relate these data in 3d to get the bell shape surface, with similar characteristics.

You can view a line/curve plot as a function of a single variable, y=f(x) , and typically, x and y are both vectors. For eg, you can plot the Gaussian bell curve as

x=linspace(-3,3,1000);
y=exp(-x.^2/2);
plot(x,y)

A surface plot, on the other hand, is a function of two variables, z=f(x,y) where x and y can be either vectors or matrices and z is a matrix. meshgrid is a very handy function that generates 2D x and y arrays from 1D vectors by proper replication.

It is the z matrix that you plot either as a 2D image (values of z are represented by colors) or a 3D plot (values of z are represented as heights along the z-axis). For eg, a 3D Gaussian bell curve can be plotted as

x=linspace(-3,3,1000);y=x';               %'
[X,Y]=meshgrid(x,y);
z=exp(-(X.^2+Y.^2)/2);
surf(x,y,z);shading interp

This is how the respective plots should look like

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM