How can I add multiple y axes to a plot?

조회 수: 2 (최근 30일)
Vincent I
Vincent I 2012년 6월 27일
댓글: Khanh 2014년 12월 27일
Hi,
I'm trying to plot the y axes on the right side of the graph but for some reason i'm unable to do so.
You are probably wondering why I'm not using different code to do this. Well' I'm trying to adapt the "addaxis" code by Harry Lee where I can add multiple real time plots with axes at the same time. The real time plots are working great, now I'm trying to figure out how to add axis with each plot.
cah=findall(handles.Axes1,'type','axes');
yl = get(cah,'ylim');
cpos = get(cah,'position');
set(cah,'box','off');
% get userdata of current axis. this will hold handles to
% additional axes and the handles to their corresponding plots
% in the main axis
axh = get(cah,'userdata');
ledge = cpos(1);
if length(axh)>=1
if length(axh)/2 == round(length(axh)/2)
rpos = get(axh{end-1}(1),'position');
redge = rpos(1);
lpos = get(axh{end}(1),'position');
ledge = lpos(1);
else
rpos = get(axh{end}(1),'position');
redge = rpos(1);
if length(axh)>1
lpos = get(axh{end-1}(1),'position');
ledge = lpos(1);
end
end
else
redge = cpos(3)+cpos(1);
ledge = cpos(1);
end
totwid = redge-ledge;
% assume axes are added on right, then left, then right, etc.
numax = length(axh)+1;
% parameters setting axis separation
axcompleft=0.12;
if numax == 1
axcompright = 0.0;
else
axcompright = 0.12;
end
if numax/2 == round(numax/2)
side = 'left';
xpos = ledge-axcompleft*totwid;
else
side = 'right';
xpos = redge+axcompright*totwid;
end
% plot in new axis to get the automatically generated ylimits
h_ax = axes('position',[xpos, cpos(2), cpos(3)*.015, cpos(4)]);
hplt = plot(handles.Axes1,x,y);
if ~exist('yl2')
yl2 = get(h_ax,'ylim');
end
set(h_ax,'yaxislocation',side);
set(h_ax,'color',get(gcf,'color'));
set(h_ax,'box','off');
set(h_ax,'xtick',[]);
set(hplt,'visible','off');
set(h_ax,'ylim',yl2);
  댓글 수: 1
Khanh
Khanh 2014년 12월 27일
What's different between your code and Harry's? Could you tell me what 'real time plots' means in detail?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by