Thread Subject: how to create a zoom out plot within a plot

Subject: how to create a zoom out plot within a plot

From: nan

Date: 21 Sep, 2009 08:50:19

Message: 1 of 3

hello everyone,
i try to plot a figure with a zoom out plot within the figure. the codes are show at the bellow, the problem is, the axes for the zoom out plot doesnt change as the limits given in the code. can anyone help me please!

many thanks
nan
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
cell_total_user=0:1680;
collided=0:1680;
x1=cell_total_user*1;
x2=collided*1;
p3=plot(cell_total_user,x1,collided,x2)
hkids = get(gca,'child')
set(hkids(1), 'marker', '*')
set(hkids(2), 'marker', 'o')
ax1 = gca;
  ax2 = axes('Position',get(ax1,'Position'),...
           'XAxisLocation','top',...
           'YAxisLocation','right',...
           'Color','none',...
           'XColor','k','YColor','k');
set(ax2,'xlim',[200 300])% axes limit for zoom out,
set(ax2, 'Units', 'normalized', 'Position', [0.25 0.65 0.25 0.25])
plot(cell_total_user,x1,collided,x2, 'marker','*') % plot in zoom axes

Subject: how to create a zoom out plot within a plot

From: Sebastiaan

Date: 21 Sep, 2009 09:32:03

Message: 2 of 3

You have to plot the data first, then set the limits. Otherwise, the limits are adjusted to the new plot. Also, all your axes properties are ignored now (location, colour, etc.). You have to add the option NextPlot (same as the 'hold on' command).

A more "robuust" piece of code is this, where you create your axes first, and then plot to that specific axes, in stead of relying on the current gca:
clear all
close all
cell_total_user=0:1680;
collided=0:1680;
x1=cell_total_user*1;
x2=collided*1;

ax1 = axes; % create axes
p3=plot(ax1, cell_total_user,x1,collided,x2) % plot to ax1
hkids = get(ax1, 'child') % get ax1 properties
set(hkids(1), 'marker', '*')
set(hkids(2), 'marker', 'o')

ax2 = axes('Position',get(ax1,'Position'),...
           'XAxisLocation','top',...
           'YAxisLocation','right',...
           'Color','none',...
           'XColor','k','YColor','k', 'NextPlot', 'add'); % make ax2. Use nexplot to maintain your settings
plot(ax2, cell_total_user,x1,collided,x2, 'marker','*') % plot in zoom axes
set(ax2,'xlim',[200 300])% axes limit for zoom out,
set(ax2, 'Units', 'normalized', 'Position', [0.25 0.65 0.25 0.25])




"nan " <njyan2005@yahoo.co.uk> wrote in message <h97eob$34j$1@fred.mathworks.com>...
> hello everyone,
> i try to plot a figure with a zoom out plot within the figure. the codes are show at the bellow, the problem is, the axes for the zoom out plot doesnt change as the limits given in the code. can anyone help me please!
>
> many thanks
> nan
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> clear all
> close all
> cell_total_user=0:1680;
> collided=0:1680;
> x1=cell_total_user*1;
> x2=collided*1;
> p3=plot(cell_total_user,x1,collided,x2)
> hkids = get(gca,'child')
> set(hkids(1), 'marker', '*')
> set(hkids(2), 'marker', 'o')
> ax1 = gca;
> ax2 = axes('Position',get(ax1,'Position'),...
> 'XAxisLocation','top',...
> 'YAxisLocation','right',...
> 'Color','none',...
> 'XColor','k','YColor','k');
> set(ax2,'xlim',[200 300])% axes limit for zoom out,
> set(ax2, 'Units', 'normalized', 'Position', [0.25 0.65 0.25 0.25])
> plot(cell_total_user,x1,collided,x2, 'marker','*') % plot in zoom axes

Subject: how to create a zoom out plot within a plot

From: nan

Date: 21 Sep, 2009 10:00:22

Message: 3 of 3

Thank you very much, Sebastiaan!

nan


"Sebastiaan" <s.breedveld@erasmusmc.REMOVE.BOO.BOO.nl> wrote in message <h97h6j$33q$1@fred.mathworks.com>...
> You have to plot the data first, then set the limits. Otherwise, the limits are adjusted to the new plot. Also, all your axes properties are ignored now (location, colour, etc.). You have to add the option NextPlot (same as the 'hold on' command).
>
> A more "robuust" piece of code is this, where you create your axes first, and then plot to that specific axes, in stead of relying on the current gca:
> clear all
> close all
> cell_total_user=0:1680;
> collided=0:1680;
> x1=cell_total_user*1;
> x2=collided*1;
>
> ax1 = axes; % create axes
> p3=plot(ax1, cell_total_user,x1,collided,x2) % plot to ax1
> hkids = get(ax1, 'child') % get ax1 properties
> set(hkids(1), 'marker', '*')
> set(hkids(2), 'marker', 'o')
>
> ax2 = axes('Position',get(ax1,'Position'),...
> 'XAxisLocation','top',...
> 'YAxisLocation','right',...
> 'Color','none',...
> 'XColor','k','YColor','k', 'NextPlot', 'add'); % make ax2. Use nexplot to maintain your settings
> plot(ax2, cell_total_user,x1,collided,x2, 'marker','*') % plot in zoom axes
> set(ax2,'xlim',[200 300])% axes limit for zoom out,
> set(ax2, 'Units', 'normalized', 'Position', [0.25 0.65 0.25 0.25])
>
>
>
>
> "nan " <njyan2005@yahoo.co.uk> wrote in message <h97eob$34j$1@fred.mathworks.com>...
> > hello everyone,
> > i try to plot a figure with a zoom out plot within the figure. the codes are show at the bellow, the problem is, the axes for the zoom out plot doesnt change as the limits given in the code. can anyone help me please!
> >
> > many thanks
> > nan
> > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> > clear all
> > close all
> > cell_total_user=0:1680;
> > collided=0:1680;
> > x1=cell_total_user*1;
> > x2=collided*1;
> > p3=plot(cell_total_user,x1,collided,x2)
> > hkids = get(gca,'child')
> > set(hkids(1), 'marker', '*')
> > set(hkids(2), 'marker', 'o')
> > ax1 = gca;
> > ax2 = axes('Position',get(ax1,'Position'),...
> > 'XAxisLocation','top',...
> > 'YAxisLocation','right',...
> > 'Color','none',...
> > 'XColor','k','YColor','k');
> > set(ax2,'xlim',[200 300])% axes limit for zoom out,
> > set(ax2, 'Units', 'normalized', 'Position', [0.25 0.65 0.25 0.25])
> > plot(cell_total_user,x1,collided,x2, 'marker','*') % plot in zoom axes

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
zoom Sprinceana 21 Sep, 2009 07:04:19
zoom in a plot Sprinceana 21 Sep, 2009 07:04:19
rssFeed for this Thread

Contact us at files@mathworks.com