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

2 Ansichten (letzte 30 Tage)
HC98
HC98 am 12 Mai 2022
Beantwortet: Voss am 13 Mai 2022
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?

Akzeptierte Antwort

Voss
Voss am 13 Mai 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

Weitere Antworten (0)

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by