"plot" and "stairs" in the same figure with different axis

조회 수: 2 (최근 30일)
Andrea Frascella
Andrea Frascella 2018년 10월 28일
댓글: madhan ravi 2018년 10월 28일
Hello guys, for first excuse me for my bad English. I'm trying to plot in the same figure a graphic with "plot" function and a graphic with "stairs" function to represent the same signal, once analog and once quantized. So, I want to visualize in one figure:
  • the analog signal using plot function, X axis at the bottom and Y axis at the left;
  • the quantized signal using stairs function, X axis at the top and Y axis at the right;
I tried to specify axis's properties but everytime the output of plot function disappears; in addition to this, I can't display even just stairs function's output with X axis on the top and Y axis on the left.
ax1 = axes('XAxisLocation','bottom','YAxisLocation','left'
ax2 = axes('XAxisLocation','top','YAxisLocation','right');
plot(ax1,P,V_ina)
hold on
stairs(ax2,st,V_adc)
The last command doesn't work in every case. I tried also to specify parent's relationship for stairs function but the code still does not work. Obviously plot and stairs work well together usign "hold on" and the same axis. There is a guide that explains how to do a similiar thing but using only "line" function; can anyone help me? It is really strange that there is a yyaxis funtion and a similiar command for X axis doesn't exist.
  댓글 수: 2
madhan ravi
madhan ravi 2018년 10월 28일
can you provide the datas to test?
Andrea Frascella
Andrea Frascella 2018년 10월 28일
The data are only 4 vectors, I attach them here. Thank you for the interest.

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

채택된 답변

madhan ravi
madhan ravi 2018년 10월 28일
편집: madhan ravi 2018년 10월 28일
x=rand(1,10);
y=1:10;
ax = gca; % current axes
ax1=plot(x,y)
hold on
ax2=stairs(x,y)
ax1=gca;
ax2 = axes('Position', get(ax1, 'Position'),'Color', 'none');
set(ax2, 'XAxisLocation', 'top','YAxisLocation','Right');
  댓글 수: 5
Andrea Frascella
Andrea Frascella 2018년 10월 28일
So, I must use plot and stairs first and after I can modify axis's position. It works, thanks a lot!
madhan ravi
madhan ravi 2018년 10월 28일
yes exactly!, Anytime :)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by