How can I add multiple y axes to a plot?

1 view (last 30 days)
Vincent I
Vincent I on 27 Jun 2012
Commented: Khanh on 27 Dec 2014
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 Comment
Khanh
Khanh on 27 Dec 2014
What's different between your code and Harry's? Could you tell me what 'real time plots' means in detail?

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!