Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 使用图形的屋顶作为另一个图形的x轴_Matlab_Plot_Graph_Matlab Figure - Fatal编程技术网

Matlab 使用图形的屋顶作为另一个图形的x轴

Matlab 使用图形的屋顶作为另一个图形的x轴,matlab,plot,graph,matlab-figure,Matlab,Plot,Graph,Matlab Figure,我已经用pcolor绘制了一个图表,它给出了下面的图表- 我的目标是使用图的屋顶(通过屋顶),我指的是最高的轴(在本例中,由y=57定义的线)作为下一个图的基础 我能够使用hold on生成以下代码- 代码(为了简洁起见,删除了一些定义轴标签等的零件)- 如您所见,直线图使用的x轴与第一个图形相同 我试图让线图位于图形的顶部。我想象这样的最终图形- 关于如何使用第一个图形的顶部,您有什么想法吗?您可以使用两个子图。以下是一个例子: data = randi(50,20,20); % so

我已经用pcolor绘制了一个图表,它给出了下面的图表-

我的目标是使用图的屋顶(通过屋顶),我指的是最高的轴(在本例中,由y=57定义的线)作为下一个图的基础

我能够使用
hold on
生成以下代码-

代码(为了简洁起见,删除了一些定义轴标签等的零件)-

如您所见,直线图使用的x轴与第一个图形相同

我试图让线图位于图形的顶部。我想象这样的最终图形-


关于如何使用第一个图形的顶部,您有什么想法吗?

您可以使用两个子图。以下是一个例子:

data =  randi(50,20,20); % some data for the pcolor
y = mean(data); % some data for the top plot
subplot(5,1,2:5) % create a subplot on the lower 4/5 part for the figure
pcolor(data) % plot the data
colormap hot;
h = colorbar('east'); % place the colorbar on the right
h.Position(1) = 0.94; % 'push' the colorbar a little more to the right
ax = gca;
pax = ax.Position; % get the position for further thightning of the axes
ax.YTick(end) = []; % delete the highest y-axis tick so it won't interfere
                    % with the first tick of the top plot
subplot(5,1,1) % create a subplot on the upper 1/5 part for the figure
plot(1:20,y) % plot the top data
ylim([0 max(y)]) % compact the y-axis a little
ax = gca;
ax.XAxis.Visible = 'off'; % delete the x-axis from the top plot
ax.Position(2) = pax(2)+pax(4); % remove the space between the subplots
这就产生了:


将所需行的所有
y
值设置为
y+57
,它们将集中在那里,而不是
0
@Adriaan,谢谢。但是如果可能的话,我希望有一个单独的y轴,从0开始绘制直线图(而不是从57开始)。如您所见,线形图的y值为0-3。我希望y轴能够反映图形的这一部分。在这种情况下,请使用自定义轴标签。如果是那样的话,可能需要手工设计,检查一下。因此,基本上你仍然使用
y=y+57
来绘制线条图,然后发明自定义
yticks=[0501052503540550]
之类的东西。然后你可以在y=57处用一条黑色实线来“模拟”你的y轴,尽管我认为你不能在上面画x记号。@Adriaan,你可能对下面的解决方案感兴趣。这似乎正是我需要的!我不得不承认没有解决方案,所以这是非常有用的。在我“接受”你的代码之前,你能评论一下吗?
data =  randi(50,20,20); % some data for the pcolor
y = mean(data); % some data for the top plot
subplot(5,1,2:5) % create a subplot on the lower 4/5 part for the figure
pcolor(data) % plot the data
colormap hot;
h = colorbar('east'); % place the colorbar on the right
h.Position(1) = 0.94; % 'push' the colorbar a little more to the right
ax = gca;
pax = ax.Position; % get the position for further thightning of the axes
ax.YTick(end) = []; % delete the highest y-axis tick so it won't interfere
                    % with the first tick of the top plot
subplot(5,1,1) % create a subplot on the upper 1/5 part for the figure
plot(1:20,y) % plot the top data
ylim([0 max(y)]) % compact the y-axis a little
ax = gca;
ax.XAxis.Visible = 'off'; % delete the x-axis from the top plot
ax.Position(2) = pax(2)+pax(4); % remove the space between the subplots