How can I add multiple y axes to a plot?

1 次查看(过去 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 中查找有关 Graphics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by