Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab multiple stacked plots

Tags:

plot

matlab

I've never seen a plot like the following (the plot in (a) ). Is it even possible?

enter image description here

like image 793
greg Avatar asked May 08 '15 22:05

greg


2 Answers

According to the profile page of @Ander Biguri

Matlab can even make your dinner, if you know how to use it.

Which answers the question, if this is even possible ;-)

All we need is basic knowledge of the axes command - the rest is just tweaking to make it look nice. Let's have a look at it:

We'll start off by creating some sample data:

t = 100:220;
x1 = -(10*(t-130)).^2;
x2 = -(10*(t-150)).^2;
x3 = -(10*(t-170)).^2;

Then we'll create an initial figure with a white background

fig = figure(1);
set(fig,'Color','w');

Now we can create a new axes object and plot x1 on it:

ax(1) = axes('Position',[0.1,0.1,0.6,0.6]);
plot(ax(1),t,x1+10^4*rand(size(x1)),'-k',t,x1,'-r');

We'll remove the box around the axes, so only the x- and y-axes remain. Further we resize the plot, so we'll have enough space for the other two plots. We also set the color to none, i.e. transparent.

set(ax(1),'Color','none');
set(ax(1),'Box','off');
set(ax(1),'Position',[0.1,0.1,0.6,0.6]);

Now we need to create the second graph. We'll just create another axes object at a position which we like:

ax(2) = axes('Position',[0.2,0.2,0.6,0.6]);
plot(ax(2),t,x2+10^4*rand(size(x2)),'-k',t,x2,'-r');
set(ax(2),'Color','none');
set(ax(2),'Box','off');

and so on:

ax(3) = axes('Position',[0.3,0.3,0.6,0.6]);
plot(ax(3),t,x3+10^4*rand(size(x3)),'-k',t,x3,'-r');
set(ax(3),'Color','none');
set(ax(3),'Box','off');

And simple as that, we get something that doesn't even look that bad:

the result

like image 56
hbaderts Avatar answered Oct 08 '22 21:10

hbaderts


Using multiple waterfall plots, as Horchler suggested:

 %// create some sample data
t=10:20:110;
x=0:1:200;
Y=bsxfun(@(x,t) normpdf(x,t,20),x,t.');                                                         %//' fix the code formatting on SO!!

%// Make a colormap to to set the colour of the lines
colormap([1 0 0;0 0 0]);caxis=[0 1];

%// Plot the first set of lines (red ones)
h1=waterfall(x,t,Y,zeros(size(Y)));
set(h1,'FaceColor','none','LineWidth',2) %// tweak the properties
hold on

%// Plot the second set of lines (black lines), just the red lines with some noise
h2=waterfall(x,t,Y+0.002*(rand(size(Y))-0.5),ones(size(Y)));
set(h2,'LineWidth',2)
hold off

view([16 28])

we can get this: enter image description here

like image 21
David Avatar answered Oct 08 '22 22:10

David