如何在Matlab中将图形绘制在彼此之上? [英] How to plot graphs above each other in Matlab?

查看:169
本文介绍了如何在Matlab中将图形绘制在彼此之上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Matlab中绘制两个(或更多)图。我希望他们在第三个之上对齐,等等。不过,情节对我而言并非如此。我也不希望它们都以不同的颜色在同一张图上,只是为了一个在另一个之上。可能吗?我正在寻找这样的命令,但没有取得任何成功。
提前感谢提示!

解决方案

如果你的意思是一个在另一个之上那么我想你需要使用的是命令。话虽如此,为了让您的情节更具可读性,我认为同一剧情中的两个以上的音阶使得它很难阅读。



Matlab的帮助页面向您展示了如何做到这一点,其要点如下所示:

= 1000. * rand(100,1);
x2 = 0:99;

%绘制第一个数据集
hl1 = line(x1,y1,'Color','r');
%获取轴并配置它
ax1 = gca;
set(ax1,'XColor','r','YColor','r')

%创建新轴
ax2 = axes('Position',get (ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color',' none',...
'XColor','k','YColor','k');
%用新轴绘制第二个数据集
hl2 = line(x2,y2,'Color','k','Parent',ax2);

以上脚本创建以下 plot ,其中一组轴为红色,另一组为黑色。



希望这会有所帮助。


I want to plot two (or more) graphs in Matlab. I want them to be aligned one above the second one above the third and so on. However subplot is not the case for me. I also don't want them both to be on the same graph in different colors, just to be one above the other. Is it possible? I'm searching for such a command but without any success. Thanks in advance for hints!

解决方案

If what you mean by "one above the other" is one "on top of another" then I think what You need to use is the axes command. Having said that, in order to have your plot be readable, I think more than two scales in the same plot makes it pretty hard to read.

This Matlab's help page shows you how to do it, the gist of it is shown in the following script:

y2 = 1000.*rand(100,1);
x2 = 0:99;

% Plot the first data set
hl1 = line(x1,y1,'Color','r');
% Get the axes and configure it
ax1 = gca;
set(ax1,'XColor','r','YColor','r')

%Create the new axes
ax2 = axes('Position',get(ax1,'Position'),...
           'XAxisLocation','top',...
           'YAxisLocation','right',...
           'Color','none',...
           'XColor','k','YColor','k');
% Plot the second data set with the new axes
hl2 = line(x2,y2,'Color','k','Parent',ax2);

The above script creates the following plot with one set of axes in red and another in black.

Hope this helps.

这篇关于如何在Matlab中将图形绘制在彼此之上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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