am able to zoom only last plot ,how to zoom other plots.please help

1 view (last 30 days)
Hi i have 3 plots in same figure,when i am zooming only last generated plot is zooming.how to select other plot individually and zoom when all other plots are displayed.here is my code,please help
x = 0:20;
N = numel(x);
y1 = rand(1,N);
y2 = 5.*rand(1,N)+5;
y3 = 50.*rand(1,N)-50;
%# Some initial computations:
axesPosition = [110 40 200 200]; %# Axes position, in pixels
yWidth = 30; %# y axes spacing, in pixels
xLimit = [min(x) max(x)]; %# Range of x values
xOffset = -yWidth*diff(xLimit)/axesPosition(3);
%# Create the figure and axes:
figure('Units','pixels','Position',[200 200 330 260]);
h1 = axes('Units','pixels','Position',axesPosition,...
'Color','w','XColor','k','YColor','r',...
'XLim',xLimit,'YLim',[0 1],'NextPlot','add');
h2 = axes('Units','pixels','Position',axesPosition+yWidth.*[-1 0 1 0],...
'Color','none','XColor','k','YColor','m',...
'XLim',xLimit+[xOffset 0],'YLim',[0 10],...
'XTick',[],'XTickLabel',[],'NextPlot','add');
h3 = axes('Units','pixels','Position',axesPosition+yWidth.*[-2 0 2 0],...
'Color','none','XColor','k','YColor','b',...
'XLim',xLimit+[2*xOffset 0],'YLim',[-50 50],...
'XTick',[],'XTickLabel',[],'NextPlot','add');
xlabel(h1,'time');
ylabel(h3,'values');
%# Plot the data:
plot1=plot(h1,x,y1,'r');
plot2=plot(h2,x,y2,'m');
plot3=plot(h3,x,y3,'b');

Accepted Answer

ChristianW
ChristianW on 7 Feb 2013
The function setAllowAxesZoom will do the job. If you add this example to your code, you are zooming in axes h1.
hz = zoom;
setAllowAxesZoom(hz,h1,true)
setAllowAxesZoom(hz,h2,false)
setAllowAxesZoom(hz,h3,false)
If you dont want to change your code all the time you want to zoom, you can create a uicontrol, like this:
hz = zoom;
hax = [h1;h2;h3];
set(gcf,'Toolbar','figure')
uicontrol('Style', 'popup','String', 'red|magenta|blue',...
'Position',[120 243 50 20],'Callback',{@zoom_opt,hz,hax});
Since the uicontrol calls the zoom_opt function whenever its used, you'll need that function:
function zoom_opt(hObj,event,hz,hax)
% Called when user activates popup menu
val = get(hObj,'Value');
W = [0 0 0];
W(val) = 1;
for i = 1:3
setAllowAxesZoom(hz,hax(i),W(i))
end
zoom on
  5 Comments
rafi abdul
rafi abdul on 8 Feb 2013
hi when i am zooming in x direction in specific range ,values are changing in x direction for red only ,when i select other tow colours and if i zoom in x direction x values are not getting changed.i want same action(change of values in selected range) for all the colours.how to proceed
ChristianW
ChristianW on 8 Feb 2013
Delete last line in function zoom_opt. (zoom on)
This will change all axes to the zoomed Xlimits:
set(hz,'ActionPostCallback',{@mypostcallback,hax},'Enable','on');
function mypostcallback(obj,evd,hax)
newLim = get(evd.Axes,'XLim');
set(hax,'XLim',newLim)
Thats how its basicly done. Iam not building in your axes offsets.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!