Adding vertical lines to subplots

조회 수: 13 (최근 30일)
Angela
Angela 2014년 4월 1일
댓글: Angela 2014년 4월 1일
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');

답변 (1개)

Joseph Cheng
Joseph Cheng 2014년 4월 1일
편집: Joseph Cheng 2014년 4월 1일
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
Angela
Angela 2014년 4월 1일
That worked great. Thanks for the quick response.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by