I wan开发者_运维知识库t 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 e.g., 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 e.g., 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
精彩评论