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

1 次查看(过去 30 天)
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?

采纳的回答

Voss
Voss 2022-5-13
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by