Matlab绘制局部放大图

可以采用axes函数在当前图中插入一个小图的方法绘制局部放大图。
如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
func = {@(x) sin(x), @(x) cos(x)};
x = linspace(0, 15);

figure;
ax1 = axes('Position', [0.11, 0.15, 0.8, 0.8]); % 主图
ax2 = axes('Position', [0.5, 0.65, 0.3, 0.25]); % 局部图

for i=1:length(func)
plot(ax1, x, func{i}(x));
hold(ax1, 'on');

plot(ax2, x, func{i}(x));
hold(ax2, 'on');
end

xlim(ax1, [0, 15])
ylim(ax1, [-1, 3])
xlabel(ax1, '$x$', 'Interpreter', 'latex');
ylabel(ax1, '$y$', 'Interpreter', 'latex');
legend(ax1, {'$sin$', '$cos$'}, 'Location', 'northwest', 'Interpreter', 'latex')

xlim(ax2, [2, 6])
ylim(ax2, [-1, -0.3])

输出:


Matlab绘制局部放大图
https://ting2938.github.io/程序设计/Matlab/Matlab绘制局部放大图/
作者
TING2938
发布于
2020年5月27日
许可协议