串联2D图 [英] Concatenating 2D plots

查看:123
本文介绍了串联2D图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中有几个二维图.在每个图中,都有一些线(每条线都是固定长度值的行向量).总会有一条基线(黑色的),其余的彩色线可能会也可能不会出现.

I have several 2D-plots in MATLAB. In each plot there are some lines (each line is a row-vector of values of fixed length). There is always a base line (black one) and the remaining colored lines may or may not be present.

,.

我需要将所有这样的图连接成一个图,如下所示:

I need to concatenate all such plots into one plot as shown below:

请注意,这些只是出于代表性的目的,但是请很好地解释我的问题.我不知道该怎么做.有人知道吗?可能是一个例子吗?而且,如上图所示,在连续级联的图之间必须有一个垂直间隙. 需要注意的几点:

Please note these are just for representational purpose but explain my problem well. I am not able to figure how to do it. Anybody got an idea? An example may be? Also, there has to be a vertical gap between the successively concatenated plots as is shown in last figure. Some points to note:

  • 所有图的y轴长度都是固定的
  • 如果每个单独图的x轴为1:m.那么最终级联图的x轴为1:(n * m),其中n是要级联的单个图的数量.

此外,由于每条彩色线对应于一种特定类型的数据,因此如何创建其图例?谢谢!

Also, since each colored line corresponds to a specific kind of data, how to create its legend? Thanks!

推荐答案

我在这里看到两个选择:1.连接到同一图,并用NaN填充以获取间距. 2.实际上有多个图并巧妙地使用了axes.

I see two options here: 1. concatenate to the same plot and pad with NaNs to obtain the gap. 2. actually have several plots and use axes in a clever way.

这是选项1的示例,首先我们将创建一些虚假数据:

Here's an example for option 1, First we'll create some fake data:

a1=rand(1,20);
b1=3+rand(1,20);
c1=6+rand(1,20);

a2=rand(1,20);
b2=3+rand(1,20);
c2=6+rand(1,20);

a3=rand(1,20);
b3=3+rand(1,20);
c3=6+rand(1,20);

这仅用于填充NaN ...

This is just for padding with NaNs...

f=@(x) [ NaN(1,round(numel(x)/5)) x ];

串联:

y1=[f(a1) f(a2) f(a3)];
y2=[f(b1) f(b2) f(b3)];
y3=[f(c1) f(c2) f(c3)];

绘图

x=1:numel(y1);
plot(x,y1,x,y2,x,y3);
set(gca,'XTickLabel',[]); 

这篇关于串联2D图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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