【MATLAB基础绘图第8棒】绘制局部放大图

MATLAB绘制局部放大图

1 工具准备

MATLAB官网-ZoomPlot(Kepeng Qiu. Matlab Central, 2022)
在这里插入图片描述
初始数据图绘制完成后,调用以下代码:

%% 添加局部放大
zp = BaseZoom();
zp.plot;

1.1 具体绘制步骤

具体绘制步骤如下:

  • 通过鼠标左键框选作图区域;
  • 鼠标右键确定后,通过鼠标左键框选需要放大的区域;
  • 鼠标右键确定后,完成局部放大图的绘制。

1.2 子坐标系(sub-coordinate system)设置

子坐标系(sub-coordinate system)默认设置:

    % theme of inserted axes (sub-axes)
    properties
        subAxesBox = 'on'
        subAxesinsertedLineWidth = 1.2
        subAxesTickDirection = 'in'
        subAxesBackgroundColor = 'w'
    end

例:去除子坐标系并设置线宽为3,具体代码如下:

    % theme of inserted axes (sub-axes)
    properties
        subAxesBox = 'off'
        subAxesinsertedLineWidth = 3
        subAxesTickDirection = 'in'
        subAxesBackgroundColor = 'w'
    end

在这里插入图片描述

1.3 放大区域(the zoomed zone)设置

放大区域(the zoomed zone)默认设置:

    % theme of the zoomed zone (figures)
    properties
        rectangleColor = 'k'
        rectangleFaceColor = 'none'
        rectangleFaceAlpha = 0
        rectangleLineStyle = '-'
        rectangleLineWidth = 1.2
        rectangleInteractionsAllowed = 'none'
    end

例:设置放大区域线条颜色及线宽为2,具体代码如下:

    % theme of the zoomed zone (figures)
    properties
        rectangleColor = 'r'
        rectangleFaceColor = 'none'
        rectangleFaceAlpha = 0
        rectangleLineStyle = '-'
        rectangleLineWidth = 2
        rectangleInteractionsAllowed = 'none'
    end

在这里插入图片描述

1.4 连接线(the connected lines)设置

连接线(the connected lines)默认设置:

    % theme of the connected lines (figures)
    properties
        % setting of lines between arrows
        figureConnectedLineStyle = ':'
        figureConnectedLineColor = 'k'
        figureConnectedLineWidth = 1.2
        % setting of start arrow
        figureConnectedLineStartHeadStyle = 'ellipse' % shape of start arrow
        figureConnectedLineStartHeadLength = 3
        figureConnectedLineStartHeadWidth = 3
        % setting of end arrow
        figureConnectedLineEndHeadStyle = 'cback2' % shape of ending arrow
        figureConnectedLineEndHeadLength = 7
        figureConnectedLineEndHeadWidth = 7
    end

例:设置箭头末端形状及颜色,具体代码如下:

    % theme of the connected lines (figures)
    properties
        % setting of lines between arrows
        figureConnectedLineStyle = ':'
        figureConnectedLineColor = 'r'
        figureConnectedLineWidth = 1.2
        % setting of start arrow
        figureConnectedLineStartHeadStyle = 'ellipse' % shape of start arrow
        figureConnectedLineStartHeadLength = 3
        figureConnectedLineStartHeadWidth = 3
        % setting of end arrow
        figureConnectedLineEndHeadStyle = 'ellipse' % shape of ending arrow
        figureConnectedLineEndHeadLength = 7
        figureConnectedLineEndHeadWidth = 7
    end

在这里插入图片描述

2 案例

2.1 案例1:基础图形(设置1个局部放大区)

成图如下:
在这里插入图片描述
MATLAB代码如下:

clc
clear
close all
%%
addpath(genpath(pwd)) 

%  basic plotting
x = linspace(-0.1*pi,2*pi, 30);
y = cell(1, 3);
y{1, 1} = 0.4*sinc(x)+0.8;
y{1, 2} = tanh(x);
y{1, 3} = exp(-sinc(x));

figure(1);
color_ = [0, 114, 189; 126, 47, 142; 162, 20, 47]/255;
ax = axes('Units', 'normalized');
hold(ax, 'on');
box(ax,'on');
set(ax, 'LineWidth', 1.2, 'TickDir', 'in');
for i = 1:3
    plot(x, y{1, i}, 'Parent', ax, 'Color', color_(i, :), 'LineWidth', 3)
end
set(gca,'Layer','top','FontSize',14,'Fontname', 'Times New Roman');


% add a zoomed zone
zp = BaseZoom();
zp.plot;

2.2 案例2:设置2个局部放大区

成图如下:
在这里插入图片描述
MATLAB代码如下:

clc
clear
close all
%% 
addpath(genpath(pwd)) 

%  basic plotting
tmp_ = 5;
t1 = 0:pi/20:8*pi;     
t2 = 8*pi:pi/20:16*pi;
y1_ = exp(-t1/tmp_ );
y2_ = exp(-t1/tmp_ ).*sin(tmp_ *t1);
t = [t1, t2];
y1 = [y1_, fliplr(y1_)];
y2 = [y2_, fliplr(y2_)];

figure(1);
plot(t, y2, 'Color', 'r', 'LineStyle', '-', 'LineWidth', 1.5) 
hold on
plot(t, y1, 'Color', 'b', 'LineStyle', ':', 'LineWidth', 1.5) 
plot(t, -y1, 'Color', 'b', 'LineStyle', ':','LineWidth', 1.5) 
xlim([min(t), max(t)])
set(gca,'Layer','top','FontSize',14,'Fontname', 'Times New Roman');

% add 2 zoomed zones
zp = BaseZoom();
zp.plot;
zp.plot;

参考

  • 4
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WW、forever

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值