Clear Filters
Clear Filters

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

2 views (last 30 days)
Hi i have 3 plots in same figure,when i am zooming only last generated plot is to select other plot individually and zoom when all other plots are 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,...
'XLim',xLimit,'YLim',[0 1],'NextPlot','add');
h2 = axes('Units','pixels','Position',axesPosition+yWidth.*[-1 0 1 0],...
'XLim',xLimit+[xOffset 0],'YLim',[0 10],...
h3 = axes('Units','pixels','Position',axesPosition+yWidth.*[-2 0 2 0],...
'XLim',xLimit+[2*xOffset 0],'YLim',[-50 50],...
%# Plot the data:

Accepted Answer

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;
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];
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
zoom on
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 to proceed
ChristianW on 8 Feb 2013
Delete last line in function zoom_opt. (zoom on)
This will change all axes to the zoomed Xlimits:
function mypostcallback(obj,evd,hax)
newLim = get(evd.Axes,'XLim');
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!