给定2d数据的3d图 [英] 3d plot with given 2d data

查看:84
本文介绍了给定2d数据的3d图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解2d数据与z轴的关系,以获得3d图

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

让我们说我有x=[-1:0.1:1],向量

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

一个y Vs x的图将具有5的峰值,并在x = 0.5处向下倾斜到两侧 如何在3d中将这些数据关联以获得具有相似特征的钟形表面.

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.

推荐答案

您可以将线/曲线图视为单个变量y=f(x)的函数,通常xy都是矢量.例如,您可以将高斯钟形曲线绘制为

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)

另一方面,表面图是两个变量z=f(x,y)的函数,其中xy可以是向量或矩阵,而z是矩阵. meshgrid 是一个非常方便的函数,可以生成2D x一维向量中的yy阵列通过适当的复制.

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.

它是z矩阵,您可以将其绘制为2D图像(z的值由颜色表示)或3D绘制(z的值表示为沿z轴的高度).例如,可以将3D高斯钟形曲线绘制为

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

这是各个图的样子

这篇关于给定2d数据的3d图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆