Matlab 3D绘图绘制奇怪的线条?

时间:2022-09-10 21:58:05

I have 3 arrays X, Y, Z that look something like this:

我有3个数组X,Y,Z看起来像这样:

x = [1, 1, 1, 2, 2, 2, 3, 3, 3]
y = [1, 2, 3, 1, 2, 3, 1, 2, 3]
z = [1, 2, 3, 2, 4, 6, 3, 6, 9]

Then I am plotting these points with plot3(x,y,z). However the result is something unexpected.. It's basically meant to appear like a log-graph, it does this but it also has extra lines. I have no idea how it's happening, maybe someone here can enlighten me!

然后我用plot3(x,y,z)绘制这些点。然而结果是意想不到的..它基本上意味着看起来像一个日志图,它做到了这一点,但它也有额外的线。我不知道它是怎么发生的,也许这里有人可以开导我!

Here is an example of my graph (obviously I've plotted my values for X, Y, Z and the arrays above are just an example of what they look like): Matlab 3D绘图绘制奇怪的线条?

这是我的图形示例(显然我已经绘制了X,Y,Z的值,上面的数组只是它们的样子):

As you can see, the bottom curved lines are the log-graph lines which I am happy to be seeing, but the one that appears above it confuse me. I tried displaying the X Y Z values that match the following pattern: X is between 110 and 120 and Y = 0.05. This should theoretically give me TWO matches for each X. ie. Between X = [110, 120], I should get 20 matches since the graph shows two lines hitting at the point Y = 0.05 for each X.

正如你所看到的,底部曲线是我很高兴看到的对数线,但是上面出现的那条线让我感到困惑。我尝试显示符合以下模式的X Y Z值:X介于110和120之间,Y = 0.05。从理论上讲,这应该为每个X提供两个匹配。即。在X = [110,120]之间,我应该得到20个匹配,因为图表显示在每个X的点Y = 0.05处击中两条线。

To make it more clear what values of X are being graphed, it's basically increments of 0.1 so between X = 120 and X = 119, it is plotting 119.0, 119.1, ... , 120.0. In any case, only two points of X, Z hit Y = 0.05 between 119-120.

为了更清楚地表示X的值是什么,它基本上是0.1的增量,因此在X = 120和X = 119之间,它绘制了119.0,119.1,......,120.0。在任何情况下,只有两点X,Z在119-120之间达到Y = 0.05。

As I was saying, I checked for the values of X, Z that matched Y = 0.05 and it only returns ONE result per X. That is, for X = [110, 120], only 10 matches returned. These values were values on the bottom lines (ie. the log-graph lines) and NOT the top line. So effectively, these lines are not meant to exist. They are definitely hitting Y = 0.05 and are between X = [110, 120] so they should be appearing as a match..

正如我所说的,我检查了匹配Y = 0.05的X,Z的值,并且每X只返回一个结果。也就是说,对于X = [110,120],只返回10个匹配。这些值是底线(即对数图线)上的值,而不是顶行。如此有效,这些线并不意味着存在。它们肯定达到Y = 0.05并且在X = [110,120]之间,因此它们应该作为匹配出现。

So there you have it. Not really sure what's going on! If someone could help, that'd be great.

所以你有它。不确定发生了什么!如果有人可以提供帮助,那就太好了。

EDIT - More Info. Even manually putting the X, Y values to the function which returns Z never reaches the values on the upper line.

编辑 - 更多信息。即使手动将X,Y值放入返回Z的函数,也不会达到上面一行的值。

Thanks.

谢谢。

2 个解决方案

#1


2  

The example for x, y and z actually illustrates your problem quite well.
You are not plotting individual curves (one for each log-plot) but rather one continuous curve. Hence your extra lines are in fact connecting one end of a log curve to the beginning of the next.
You have to break up your plot command.

x,y和z的示例实际上很好地说明了您的问题。您没有绘制单个曲线(每个对数图一个),而是绘制一条连续曲线。因此,您的额外线条实际上将日志曲线的一端连接到下一条曲线的开头。你必须打破你的情节命令。

Edit
In the end it will require knowledge of your dataset, but for the x, y, z you provided above, this will work to produce three independent curves instead of one:

编辑最后,它将需要您的数据集知识,但对于您在上面提供的x,y,z,这将生成三条独立曲线而不是一条曲线:

x = [1, 1, 1, 2, 2, 2, 3, 3, 3];
y = [1, 2, 3, 1, 2, 3, 1, 2, 3];
z = [1, 2, 3, 2, 4, 6, 3, 6, 9];

DATASET_SIZE = 3;

hold on;

for i=1:size(x,2)/DATASET_SIZE

    plot3(x((i-1)*DATASET_SIZE+1:i*DATASET_SIZE),y((i-1)*DATASET_SIZE+1:i*DATASET_SIZE),z((i-1)*DATASET_SIZE+1:i*DATASET_SIZE));
    plot3(x(i*DATASET_SIZE+1:2*DATASET_SIZE),y(i*DATASET_SIZE+1:2*DATASET_SIZE),z(i*DATASET_SIZE+1:2*DATASET_SIZE));
    plot3(x(2*DATASET_SIZE+1:3*DATASET_SIZE),y(2*DATASET_SIZE+1:3*DATASET_SIZE),z(2*DATASET_SIZE+1:3*DATASET_SIZE));

    view(3)

end  

Edit 2

编辑2

An easy way of finding out if this "problem" occured, is using the Data Cursor in the MATLAB plot window. Place it anywhere on your graph and use the up or down arrow keys to move around. If you can move along the entire length of the plot, it is a continuous line. Furthermore, you should see the Cursor jump from the "end" of one curve to the "start" of the next.

找出这个“问题”的简单方法是使用MATLAB绘图窗口中的数据光标。将它放在图表的任何位置,然后使用向上或向下箭头键移动。如果你可以沿着图的整个长度移动,那么它就是一条连续的线。此外,您应该看到Cursor从一条曲线的“end”跳到下一条曲线的“start”。

#2


0  

I had the same problem using surface(x,y,z) and addressed the issue by changing the renderer. MATLAB has 3 different renderers for plotting data and by default the openGL renderer plots as you have shown. You can view hwich renderer your figure uses with GET(gcf). You can change renderer as I have done using: set(gcf,'Renderer','painters') The 3rd renderer I believe is zbuffer and may work as well.

我使用表面(x,y,z)遇到了同样的问题,并通过更改渲染器来解决问题。 MATLAB有3种不同的渲染器用于绘制数据,默认情况下,openGL渲染器绘制如图所示。您可以使用GET(gcf)查看您的数字使用的hwich渲染器。您可以像我使用的那样更改渲染器:set(gcf,'Renderer','painters')我认为第三个渲染器是zbuffer并且也可以正常工作。

#1


2  

The example for x, y and z actually illustrates your problem quite well.
You are not plotting individual curves (one for each log-plot) but rather one continuous curve. Hence your extra lines are in fact connecting one end of a log curve to the beginning of the next.
You have to break up your plot command.

x,y和z的示例实际上很好地说明了您的问题。您没有绘制单个曲线(每个对数图一个),而是绘制一条连续曲线。因此,您的额外线条实际上将日志曲线的一端连接到下一条曲线的开头。你必须打破你的情节命令。

Edit
In the end it will require knowledge of your dataset, but for the x, y, z you provided above, this will work to produce three independent curves instead of one:

编辑最后,它将需要您的数据集知识,但对于您在上面提供的x,y,z,这将生成三条独立曲线而不是一条曲线:

x = [1, 1, 1, 2, 2, 2, 3, 3, 3];
y = [1, 2, 3, 1, 2, 3, 1, 2, 3];
z = [1, 2, 3, 2, 4, 6, 3, 6, 9];

DATASET_SIZE = 3;

hold on;

for i=1:size(x,2)/DATASET_SIZE

    plot3(x((i-1)*DATASET_SIZE+1:i*DATASET_SIZE),y((i-1)*DATASET_SIZE+1:i*DATASET_SIZE),z((i-1)*DATASET_SIZE+1:i*DATASET_SIZE));
    plot3(x(i*DATASET_SIZE+1:2*DATASET_SIZE),y(i*DATASET_SIZE+1:2*DATASET_SIZE),z(i*DATASET_SIZE+1:2*DATASET_SIZE));
    plot3(x(2*DATASET_SIZE+1:3*DATASET_SIZE),y(2*DATASET_SIZE+1:3*DATASET_SIZE),z(2*DATASET_SIZE+1:3*DATASET_SIZE));

    view(3)

end  

Edit 2

编辑2

An easy way of finding out if this "problem" occured, is using the Data Cursor in the MATLAB plot window. Place it anywhere on your graph and use the up or down arrow keys to move around. If you can move along the entire length of the plot, it is a continuous line. Furthermore, you should see the Cursor jump from the "end" of one curve to the "start" of the next.

找出这个“问题”的简单方法是使用MATLAB绘图窗口中的数据光标。将它放在图表的任何位置,然后使用向上或向下箭头键移动。如果你可以沿着图的整个长度移动,那么它就是一条连续的线。此外,您应该看到Cursor从一条曲线的“end”跳到下一条曲线的“start”。

#2


0  

I had the same problem using surface(x,y,z) and addressed the issue by changing the renderer. MATLAB has 3 different renderers for plotting data and by default the openGL renderer plots as you have shown. You can view hwich renderer your figure uses with GET(gcf). You can change renderer as I have done using: set(gcf,'Renderer','painters') The 3rd renderer I believe is zbuffer and may work as well.

我使用表面(x,y,z)遇到了同样的问题,并通过更改渲染器来解决问题。 MATLAB有3种不同的渲染器用于绘制数据,默认情况下,openGL渲染器绘制如图所示。您可以使用GET(gcf)查看您的数字使用的hwich渲染器。您可以像我使用的那样更改渲染器:set(gcf,'Renderer','painters')我认为第三个渲染器是zbuffer并且也可以正常工作。