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

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 日

0 投票

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 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 28 日
try the above
Andrea Frascella
Andrea Frascella 2018 年 10 月 28 日
I want the X axis for stairs function on the top, this code use the same X axis for the two functions.
madhan ravi
madhan ravi 2018 年 10 月 28 日
see edited now (example)
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 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by