Why is my text going in the wrong subplot?
Mostrar comentarios más antiguos
I'm trying to add text to two subplots stacked vertically. The first add is successful. The second adds go into the top subplot instead of the bottom. The horzontal position is correct, as is the vertical as far as I can tell. The text just seems to be the wrong subplot. I'm using the 'Parent' property in the "text()" call, but it seems to be ignored.
To be clear, it behaves the same way without the 'Parent' property.
The plotted curves are correct in the lower subplot.
What am I doing wrong, please?
figure ;
h1 = subplot(2,1,1) ;
plot(M_lag,M_res) ;
title([ 'DLY = ' sprintf('%d',DLY) ]) ;
ax1 = gca ;
ax1.XTick = -(round(length(M_res),-1)+10)/2:50:round(length(M_res)/2,-1)+10 ;
hold on
plot([ M_dly M_dly ],ax1.YLim(2)*[ 0.03 0.16 ],'b') ;
text('String',sprintf('%d',M_dly),'Position',[ M_dly ax1.YLim(2)*0.16 0 ], ...
'HorizontalAlignment','center','VerticalAlignment','bottom','Parent',h1) ;
h2 = subplot(2,1,2) ;
plot(beg_window:end_window,ref_,'b',beg_window:end_window,res_,'m') ;
title('ref + resp wave') ;
ax2 = gca ;
hold on
plot([ peak_idx peak_idx ],ax2.YLim(2)*[ 0.03 0.16 ],'b') ;
plot([ peak_idx+DLY peak_idx+DLY ],ax2.YLim(2)*[ 0.03 0.16 ],'b') ;
text('String',sprintf('%d',peak_idx),'Position',[ peak_idx ax1.YLim(2)*0.16 0 ], ...
'HorizontalAlignment','center','VerticalAlignment','bottom','Parent',h2) ;
text('String',sprintf('%d',peak_idx+DLY),'Position',[ peak_idx+DLY ax1.YLim(2)*0.16 0 ], ...
'HorizontalAlignment','center','VerticalAlignment','bottom','Parent',h2) ;
5 comentarios
madhan ravi
el 12 de Dic. de 2018
provide the datas
madhan ravi
el 12 de Dic. de 2018
Sorry I wasn't clear on this. The "text()" statement in the first section (subplot (2,1, 1)), adding 'M_dly', is the "first add". It is placed correctly.
The two "text()" statements in the second section (subplot (2,1, 2)), 'peak_idx' and 'peak_idx+DLY' are the "second add". The two text string show up in the upper subplot(2,1,1).
Wis
el 12 de Dic. de 2018
madhan ravi
el 12 de Dic. de 2018
yes ofcourse you can press the option insert and then attach your file
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Language Support en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!