am able to zoom only last plot ,how to zoom other plots.please help
1 view (last 30 days)
Show older comments
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');
0 Comments
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;
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
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!