在MATLAB中绘制函数的均匀间隔高度线

时间:2015-07-11 17:47:10

标签: matlab plot contour

我想使用MATLAB绘制函数的高度线(当然用矩阵表示)。

我熟悉轮廓,但是轮廓在均匀间隔的高度绘制线条,而我希望看到线条(带有高度标签),在绘制时彼此保持恒定距离。

这意味着如果一个函数在一个区域内快速增长,我将无法获得具有密集高度线的图,但只有几条线,距离均匀。

我试图在轮廓帮助页面中找到这样的选项,但看不到任何内容。有内置功能吗?

2 个答案:

答案 0 :(得分:3)

没有内置函数来执行此操作(据我所知)。您必须意识到,在一般情况下,您不能拥有既代表iso值又以固定距离间隔的线条。这仅适用于具有特殊缩放属性的绘图,而且这不是一般情况。

话虽如此,你可以想象通过使用指定图表水平的语法来接近你想要的情节:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div id="box1"></div>
<div id="box2"></div>
<div id="box3">CLONE AND APPEND ME AS ONLY DIV TO SHOW IN BODY</div>
<div id="box4"></div>
</body>

所以你需要的是高度值的良好向量... contour(Z,v) draws a contour plot of matrix Z with contour lines at the data values specified in the monotonically increasing vector v. ... 。为此,我们可以采用经典的Matlab例子:

v

enter image description here

并将其转换为:

[X,Y,Z] = peaks;
contour(X,Y,Z,10);
axis equal
colorbar

enter image description here

结果可能不如你预期的那么好,但这是我能想到的最好的,因为你所要求的是,再次,不可能。

最佳,

答案 1 :(得分:2)

您可以做的一件事是,不是将轮廓绘制在相同的空间级别(这是将整数传递给轮廓时会发生的情况),而是在数据的固定percentiles处绘制轮廓(这需要将水平向量传递给轮廓):

Z = peaks(100);  % generate some pretty data
nlevel = 30;

subplot(121)
contour(Z, nlevel)  % spaced equally between min(Z(:)) and max(Z(:))
title('Contours at fixed height')

subplot(122)
levels = prctile(Z(:), linspace(0, 100, nlevel));
contour(Z, levels);  % at given levels
title('Contours at fixed percentiles')

结果: enter image description here

对于右图,线条对于大部分图像具有稍微相等的间距。请注意,间距只是大致相等,除了一些微不足道的情况外,不可能在整个图像上得到相等的间距。

相关问题