How to stop seperate axes plotting over the top of one anotner?

1 view (last 30 days)
I have some code which plots on the same figure a smaller set of axes to zoom in on a specific area of the plot. This works great:
x = [-10:1E-3:10];
y = sin(x);
figure(1)
plot(x, y)
grid on
box on
axes('Position',[.40 .33 .45 .24])
plot(x,y)
ylim([0, 1])
title('Closer look')
grid on
box off
But the problem is, when I run the script again, it plots over the top of the previous set of iset axes and creates a mess. Any way to fix this?

Accepted Answer

Voss
Voss on 13 May 2022
One way would be to plot into a new figure each time, instead of specifying to plot into figure 1 each time:
x = [-10:1E-3:10];
y = sin(x);
% figure(1)
figure() % create a new figure
plot(x, y)
grid on
box on
axes('Position',[.40 .33 .45 .24])
plot(x,y)
ylim([0, 1])
title('Closer look')
grid on
box off

More Answers (0)

Categories

Find more on Visual Exploration in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!