本文介绍了子图如何工作,MATLAB中的子图(121)和子图(1,2,1)有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我不清楚subplot的工作方式.具体来说,在MATLAB中subplot(121)subplot(1,2,1)有什么区别?我试图搜索subplot文档,但似乎找不到我想要的东西.

I am a bit unclear with how subplot works. Specifically, what is the difference between subplot(121) and subplot(1,2,1) in MATLAB? I have tried to search the subplot documentation, but I can't seem to find what I am looking for.

推荐答案

长话短说,没有区别. subplot的工作方式如下:

Long story short, there is no difference. How subplot works is the following:

subplot(m,n,p); %//or
subplot(mnp);

您在subplot中使用了三个数字. subplot在同一窗口中放置多个数字.您可以将图放置在m x n网格内,其中m包含行数,而n包含图中的列数. p确定要在网格中放置图的位置.数字p1增大到m x n,并且曲线图从左到右,从上到下放置.

You have three numbers that are used within subplot. subplot places multiple figures within the same window. You can place plots within a m x n grid, where m contains the number of rows and n contains the number of columns in your figure. p determines where you want to place your plot within the grid. The number p increases from 1 up to m x n, and the plots are placed from left to right, and top to bottom.

在这种情况下,当您执行subplot(1,2,1);subplot(121);时,希望具有一个行和两个列的数字.最后一个数字p=1表示您希望将图放置在大多数列中.当您执行subplot(1,2,2);subplot(122);时,这是p=2时,您希望将图放置在大多数 right 列中.

In this case, when you do subplot(1,2,1); or subplot(121);, you would like to have one row and two columns worth of figures. The last number, p=1 means that you wish to place the plot in the left most column. When you do subplot(1,2,2); or subplot(122);, this is when p=2 and you wish to place the plot in the right most column.

subplot的使用方式如下:

  1. 首先确定要在此窗口中(mn)要多少列的列.
  2. 产生一个空白的figure窗口
  3. 对于要创建的每个图...
    • 致电subplot并选择要显示图的正确位置.
    • 编写必要的代码以创建绘图,就像只占用单个窗口的绘图一样.
    • 绘制数据
  1. Determine how many rows and columns of plots you want within this window first (i.e. m and n).
  2. Spawn a blank figure window
  3. For each plot you want to create...
    • Call subplot and choose the right location(s) of where you want the plot to appear.
    • Write the necessary code to create your plot like you would for just a plot occupying a single window.
    • Plot your data

这是一个说明性示例.让我们创建一个窗口,该窗口在同一窗口中具有 2 行和 3 列的图形.因此:

Here is an illustrative example. Let's create a window that has two rows and three columns worth of figures within the same window. As such:

figure;
rng(10); %// Set seed for reproducibility
subplot(2,3,1);
x = rand(100,1);
y = rand(100,1);
plot(x,y,'b.');
title('First plot');
subplot(2,3,2);
x = rand(100,1);
y = rand(100,1);
plot(x,y,'b.');
title('Second plot');
subplot(2,3,3);
x = rand(100,1);
y = rand(100,1);
plot(x,y,'b.');
title('Third plot');
subplot(2,3,4);
x = rand(100,1);
y = rand(100,1);
plot(x,y,'b.');
title('Fourth plot');
subplot(2,3,5);
x = rand(100,1);
y = rand(100,1);
plot(x,y,'b.');
title('Fifth plot');
subplot(2,3,6);
x = rand(100,1);
y = rand(100,1);
plot(x,y,'b.');
title('Sixth plot');

上面的代码所做的是,我们为成对的xy生成随机的点集,每个点分别为100 x 1,并将它们绘制在整个窗口内的多个位置.请注意,subplot的最后一个参数线性增加,而前两个参数保持不变.您必须必须确保知道在开始绘制之前在整个窗口中要拥有多少个图形.上面的代码描述的图形如下所示:

What the above code does is that we generate random sets of points that are 100 x 1 each for pairs of x and y and we plot them in multiple locations within the overall window. Notice that the last parameter of subplot increases linearly, while the first two parameters stay the same. You must make sure that you know how many figures you want within the overall window before you start plotting. The figure that the code above describes looks like the following:

您还可以为p指定点的向量.但是,如果您采用这种方式,则必须以这种方式调用subplot:subplot(m,n,p);.如果p单个数字,则subplot(m,n,p);subplot(mnp)都可以使用.

You can also specify a vector of points for p. However, should you do it this way, you must call subplot this way: subplot(m,n,p);. If p is a single number, then either subplot(m,n,p); or subplot(mnp) will work.

如果您将p指定为向量,则将执行的操作是您制作的绘图将在同一图形窗口中占据多个空格/插槽.例如,如果您这样做:subplot(2,3,1:3);,这将占用一个绘图并占据图形的整个第一行.然后,您可以在插槽4、5和6中发布更多地块.换句话说:

If you specify p to be a vector, what this will do is that one plot you make will occupy multiple spaces / slots within the same figure window. As an example, if you did: subplot(2,3,1:3);, this will take one plot and occupy the entire first row of your figure. You can then issue more plots in slots 4, 5 and 6. In other words:

figure;
rng(10); %// Set seed for reproducibility
subplot(2,3,1:3);
x = rand(100,1);
y = rand(100,1);
plot(x,y,'b.');
title('First plot');
subplot(2,3,4:5);
x = rand(100,1);
y = rand(100,1);
plot(x,y,'b.');
title('Second plot');
subplot(2,3,6);
x = rand(100,1);
y = rand(100,1);
plot(x,y,'b.');
title('Third plot');

该图看起来像:

如您所见,我们在第一张图上使用subplot(2,3,1:3);占据了第一行.第二个图使用subplot(2,3,4:5);占用插槽p=4,p=5.这占据了第二行以及第一和第二列.最后,我们的最后一个图使用subplot(2,3,6);占据了第二行,第三列.请记住,插槽从左到右,从上到下,p不仅可以是单个数字,而且还可以是向量.如果您想占据前两行和两列,则可以执行subplot(2,3,[1 2 4 5]);现在,如果您想占据整个最右边的列,则可以执行subplot(2,3,[3 6]);,或者想要在最右边的列中找到最上面的位置,可以执行subplot(2,3,3);subplot(233);,然后,如果要处理最后一列中的最后一个位置,并且在右下角,可以执行subplot(2,3,6);

As you can see, we have occupied the first row using subplot(2,3,1:3); with the first plot. The second plot occupies slots p=4,p=5 using subplot(2,3,4:5);. This occupies the second row, and first and second columns. Finally our last plot occupies the second row, third column using subplot(2,3,6);. Remember, the slots go from left to right and top to bottom, and p can not only be a single number but a vector as well. If you wanted to occupy the first two rows and two columns, you would do subplot(2,3,[1 2 4 5]); Now, if you wanted to occupy the entire right most column, you can do subplot(2,3,[3 6]);, or if you just want the top most location in the right most column, you can do subplot(2,3,3); or subplot(233);, then if you want to tackle the last location in the last column and at the bottom right, you can do subplot(2,3,6); or subplot(236);

我想确保您记得的最后一件事是,您需要确保在决定显示自己的情节之前先致电subplot .完成后,切换到下一个插槽并继续工作.

One final thing that I want to make sure that you remember is that you need to make sure you call subplot before you decide to show your plot. Once you're finished, switch over to the next slot and keep working.

希望这会有所帮助!祝你好运!

Hope this helps! Good luck!

这篇关于子图如何工作,MATLAB中的子图(121)和子图(1,2,1)有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 10:54