Adding vertical lines to subplots

13 vues (au cours des 30 derniers jours)
Angela
Angela le 1 Avr 2014
Commenté : Angela le 1 Avr 2014
I'd like to add vertical lines to two subplots to indicate censored time points along different time series. However, when I run the script, they only show up on the second subplot. How would I apply vertical lines to both? Thanks alot!
fulldata_1=load('timeseries_1.1D');
censordata_1=load('censor_1.txt');
fulldata_2=load('timeseries_2.1D');
censordata_2=load('censor_2.txt');
fig=figure;
h1 = subplot(2,1,1);
h2 = subplot(2,1,2);
C1=censordata_1;
C2=censordata_2;
plot(h1,fulldata_1);
line([C1 C1],get(h1,'YLim'),'Color',[1 0 0]);
title(h1,'DVARS Censor');
plot(h2,fulldata_RMSD);
line([C2 2],get(h2,'YLim'),'Color',[1 0 0]);
title(h2,'RMSD Censor');

Réponses (1)

Joseph Cheng
Joseph Cheng le 1 Avr 2014
Modifié(e) : Joseph Cheng le 1 Avr 2014
you'll have to set the active axes before you do each line. Subplot h2 was the only one with the lines because it was the last item created and thus set as the current active axes. using axes() it will set the axes you wish to work with.
h1 = subplot(2,1,1);
h2 = subplot(2,1,2);
plot(h1,rand(10));
axes(h1)
line([2 2],get(h1,'YLim'),'Color',[1 0 0]);
title(h1,'DVARS Censor');
plot(h2,rand(5));
axes(h2)
line([4 4],get(h2,'YLim'),'Color',[1 0 0]);
title(h2,'RMSD Censor');
  1 commentaire
Angela
Angela le 1 Avr 2014
That worked great. Thanks for the quick response.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by