Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
817 views
in Technique[技术] by (71.8m points)

matlab - Concatenating 2D plots

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.

plot 1 , plot 2.

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

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-axis is of fixed length for all plots
  • if x-axis of each individual plot is 1:m. Then x-axis of final concatenated plot is 1:(n*m), where n is the number of individual plots to be concatenated.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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);

This is just for padding with NaNs...

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

Concatenating:

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

plotting

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

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...