Stacked plot /waterfall plots to visulaise figures

46 vues (au cours des 30 derniers jours)
Ramesh Bala
Ramesh Bala le 10 Sep 2021
Commenté : Ramesh Bala le 13 Sep 2021
I have in total 6 signals and would like to see all in a single plot.Since all having same X axis and Y axis (shall normalise it).
How shall I see all in a single waterfall plot?
Thanks in advance.
t=[0:.01:6]*1e-5;
e=zeros(length(t),6);
e(200:end,1)=12.5*cos(1.3e6*t(200:end) ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,2)=11.8*cos(1.3e6*t(200:end)+pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,3)= 8*cos(1.3e6*t(200:end)-pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,4)= 6.2*cos(1.3e6*t(200:end)+pi ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,5)= 7.2*cos(1.3e6*t(200:end)+pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,6)= 8.2*cos(1.3e6*t(200:end)-pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
%combined plot
plot(t,e(:,1),'r-',t,e(:,2),'g-',t,e(:,3),'b-',t,e(:,4),'c-',t,e(:,5),'m-',t,e(:,6),'y-');
xlabel('Time (s)'); ylabel('Strain');
legend('5','10','20','30','40','50');

Réponse acceptée

Dave B
Dave B le 10 Sep 2021
Modifié(e) : Dave B le 10 Sep 2021
If you want to put these data into a waterfall, you can do waterfall(e') but that won't get your time axis correct. Using meshgrid is an easy way to get x and y values in the right shape for waterfall (or mesh)
t=[0:.01:6]*1e-5;
e=zeros(length(t),6);
e(200:end,1)=12.5*cos(1.3e6*t(200:end) ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,2)=11.8*cos(1.3e6*t(200:end)+pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,3)= 8*cos(1.3e6*t(200:end)-pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,4)= 6.2*cos(1.3e6*t(200:end)+pi ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,5)= 7.2*cos(1.3e6*t(200:end)+pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,6)= 8.2*cos(1.3e6*t(200:end)-pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
n = [5 10 20 30 40 50]; % guessing from legend
[xi,yi] = meshgrid(t,n);
waterfall(xi,yi,e')
  4 commentaires
Dave B
Dave B le 11 Sep 2021
These aren't so difficult, it's just adding an offset to each line and then you can use plot (as you did originally).
When I've had to do this kind of thing I find it easier to do a bit of rescaling (i.e. make things go between 0 and 1) and then add a fixed offset rather than computing the offsets. It's really a matter of preference. The function rescale is awesome for this, it'll do your whole matrix by default which is a nice way to preserve the relationship between heights. If you want them all to take the same range you'll have to adjust your strategy a little.
One thing that you lose from stackedplot is the separate y axis labels. I imagine this as a hierarchy - a 'which line' followed by a 'units in that line'. In my experience in these plots I often don't care about specific y values, or I can include a little scalebar to indicate the y scale. Below I just label which line it is
t=[0:.01:6]*1e-5;
e=zeros(length(t),6);
e(200:end,1)=12.5*cos(1.3e6*t(200:end) ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,2)=11.8*cos(1.3e6*t(200:end)+pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,3)= 8*cos(1.3e6*t(200:end)-pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,4)= 6.2*cos(1.3e6*t(200:end)+pi ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,5)= 7.2*cos(1.3e6*t(200:end)+pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,6)= 8.2*cos(1.3e6*t(200:end)-pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
offset_e=bsxfun(@plus,rescale(e),1:6);
% bsxfun might feel a little cryptic, an alternative is:
% offset_e = rescale(e) + repmat(1:6,height(e),1);
plot(t,offset_e,'LineWidth',1)
yticks(offset_e(1,:))
yticklabels(1:6)
axis padded
box off
Ramesh Bala
Ramesh Bala le 13 Sep 2021
Thanks Dave

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Geographic Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by