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

3 次查看(过去 30 天)
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.

采纳的回答

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!

请先登录,再进行评论。

更多回答(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